Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more granular file change events based on VS Code file create/delete events #1805

Merged
merged 7 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/features/changeForwarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {Disposable, Uri, workspace} from 'vscode';
import {OmniSharpServer} from '../omnisharp/server';
import * as serverUtils from '../omnisharp/utils';
import { FileChangeType } from '../omnisharp/protocol';

function forwardDocumentChanges(server: OmniSharpServer): Disposable {

Expand All @@ -31,25 +32,30 @@ function forwardDocumentChanges(server: OmniSharpServer): Disposable {

function forwardFileChanges(server: OmniSharpServer): Disposable {

function onFileSystemEvent(uri: Uri): void {
if (!server.isRunning()) {
return;
}

let req = { FileName: uri.fsPath };

serverUtils.filesChanged(server, [req]).catch(err => {
console.warn(`[o] failed to forward file change event for ${uri.fsPath}`, err);
return err;
});
function onFileSystemEvent(changeType: FileChangeType): (Uri) => void {
return function(uri: Uri)
{
if (!server.isRunning()) {
return;
}

let req = { FileName: uri.fsPath, changeType};

serverUtils.filesChanged(server, [req]).catch(err => {
console.warn(`[o] failed to forward file change event for ${uri.fsPath}`, err);
return err;
});
};
}

const watcher = workspace.createFileSystemWatcher('**/*.*');
let d1 = watcher.onDidCreate(onFileSystemEvent);
let d2 = watcher.onDidChange(onFileSystemEvent);
let d3 = watcher.onDidDelete(onFileSystemEvent);
let d1 = watcher.onDidCreate(onFileSystemEvent(FileChangeType.Create));
let d2 = watcher.onDidDelete(onFileSystemEvent(FileChangeType.Delete));

// In theory we don't need to subscribe to "change" notifications
// because we already get them through the buffer update request

return Disposable.from(watcher, d1, d2, d3);
return Disposable.from(watcher, d1, d2);
}

export default function forwardChanges(server: OmniSharpServer): Disposable {
Expand Down
11 changes: 11 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ export interface PackageDependency {
Name: string;
Version: string;
}

export interface FilesChangedRequest extends Request{
ChangeType: FileChangeType;
}

export enum FileChangeType
{
Change = "Change",
Create = "Create",
Delete = "Delete"
}

export namespace V2 {

Expand Down