Skip to content

[BUG] 修改文件,发现 fileServiceClient.onFilesChanged 会触发 2 次 #4628

@shooterRao

Description

@shooterRao

问题描述

修改文件,fileServiceClient.onFilesChanged 会触发 2 次

使用 3.9.0 版本的 @opensumi/ide-file-service包用来兼容目录文件变化,修改目录里面的任意文件,发现fileServiceClient.onFilesChanged 会触发2次。第一次 event 的 FileChangeType 为 1(ADDED),第二次 event 的 FileChangeType 为 0(UPDATED)。实际上只对已有的文件进行修改,并未产生新建操作。在@opensumi/ide-file-service 3.6.4 版本正常,但在 3.9.0 版本会出现此问题。

复现路径

基于 mac arm64 electron 34.4.0 环境,在某个 browser 服务中写以下代码

import { IFileServiceClient, IFileServiceWatcher } from '@opensumi/ide-file-service';

@Injectable()
@Domain(ClientAppContribution)
export class CompileServiceClient extends RPCService implements ICompileServiceClient, ClientAppContribution { 
  @Autowired(IFileServiceClient)
  private readonly fileService: IFileServiceClient;

 private fileWatcher: IFileServiceWatcher | undefined;

  onDidStart() {
    // 创建文件监听器
    this.fileWatcher = await this.fileService.watchFileChanges(new URI(projectPath), [
      '**/node_modules/**',
      '**/dist/**',
      '**/.git/**'
    ]);

    this.fileWatcher.onFilesChanged((events) => {
      // ❓问题点:修改被 fileService watch 目录里面任意文件,回调都会触发2次
    })
  }
}

预期表现

修改文件,onFilesChanged 只触发1次。

环境信息(Environment)

  • OS: [macOS 15.3 Apple M2]
  • Electron: [34.4.0]
  • OpenSumi Version: [3.9.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions