66import { Uri , workspace } from 'vscode' ;
77import { OmniSharpServer } from '../omnisharp/server' ;
88import * as serverUtils from '../omnisharp/utils' ;
9- import { FileChangeType , LinePositionSpanTextChange } from '../omnisharp/protocol' ;
9+ import { FileChangeType } from '../omnisharp/protocol' ;
1010import { IDisposable } from '../Disposable' ;
1111import CompositeDisposable from '../CompositeDisposable' ;
1212
@@ -15,31 +15,15 @@ function forwardDocumentChanges(server: OmniSharpServer): IDisposable {
1515 return workspace . onDidChangeTextDocument ( event => {
1616
1717 let { document, contentChanges } = event ;
18- if ( document . isUntitled || document . languageId !== 'csharp' || document . uri . scheme !== 'file' ) {
19- return ;
20- }
21-
22- if ( contentChanges . length === 0 ) {
23- // This callback fires with no changes when a document's state changes between "clean" and "dirty".
18+ if ( document . isUntitled || document . languageId !== 'csharp' || document . uri . scheme !== 'file' || contentChanges . length === 0 ) {
2419 return ;
2520 }
2621
2722 if ( ! server . isRunning ( ) ) {
2823 return ;
2924 }
3025
31- const lineChanges = contentChanges . map ( function ( change ) : LinePositionSpanTextChange {
32- const range = change . range ;
33- return {
34- NewText : change . text ,
35- StartLine : range . start . line ,
36- StartColumn : range . start . character ,
37- EndLine : range . end . line ,
38- EndColumn : range . end . character
39- } ;
40- } ) ;
41-
42- serverUtils . updateBuffer ( server , { Changes : lineChanges , FileName : document . fileName , ApplyChangesTogether : true } ) . catch ( err => {
26+ serverUtils . updateBuffer ( server , { Buffer : document . getText ( ) , FileName : document . fileName } ) . catch ( err => {
4327 console . error ( err ) ;
4428 return err ;
4529 } ) ;
@@ -54,28 +38,7 @@ function forwardFileChanges(server: OmniSharpServer): IDisposable {
5438 return ;
5539 }
5640
57- if ( changeType === FileChangeType . Change ) {
58- const docs = workspace . textDocuments . filter ( doc => doc . uri . fsPath === uri . fsPath && isCSharpCodeFile ( doc . uri ) ) ;
59- if ( Array . isArray ( docs ) && docs . some ( doc => ! doc . isClosed ) ) {
60- // When a file changes on disk a FileSystemEvent is generated as well as a
61- // DidChangeTextDocumentEvent.The ordering of these is:
62- // 1. This method is called back. vscode's TextDocument has not yet been reloaded, so it has
63- // the version from before the changes are applied.
64- // 2. vscode reloads the file, and fires onDidChangeTextDocument. The document has been updated,
65- // and the changes have the delta.
66- // If we send this change to the server, then it will reload from the disk, which means it will
67- // be synchronized to the version after the changes. Then, onDidChangeTextDocument will fire and
68- // send the delta changes, which will cause the server to apply those exact changes. The results
69- // being that the file is now in an inconsistent state.
70- // If the document is closed, however, it will no longer be synchronized, so the text change will
71- // not be triggered and we should tell the server to reread from the disk.
72- // This applies to C# code files only, not other files significant for OmniSharp
73- // e.g. csproj or editorconfig files
74- return ;
75- }
76- }
77-
78- const req = { FileName : uri . fsPath , changeType } ;
41+ let req = { FileName : uri . fsPath , changeType } ;
7942
8043 serverUtils . filesChanged ( server , [ req ] ) . catch ( err => {
8144 console . warn ( `[o] failed to forward file change event for ${ uri . fsPath } ` , err ) ;
@@ -84,19 +47,14 @@ function forwardFileChanges(server: OmniSharpServer): IDisposable {
8447 } ;
8548 }
8649
87- function isCSharpCodeFile ( uri : Uri ) : Boolean {
88- const normalized = uri . path . toLocaleLowerCase ( ) ;
89- return normalized . endsWith ( ".cs" ) || normalized . endsWith ( ".csx" ) || normalized . endsWith ( ".cake" ) ;
90- }
91-
9250 function onFolderEvent ( changeType : FileChangeType ) : ( uri : Uri ) => void {
9351 return async function ( uri : Uri ) {
9452 if ( ! server . isRunning ( ) ) {
9553 return ;
9654 }
9755
9856 if ( changeType === FileChangeType . Delete ) {
99- const requests = [ { FileName : uri . fsPath , changeType : FileChangeType . DirectoryDelete } ] ;
57+ let requests = [ { FileName : uri . fsPath , changeType : FileChangeType . DirectoryDelete } ] ;
10058
10159 serverUtils . filesChanged ( server , requests ) . catch ( err => {
10260 console . warn ( `[o] failed to forward file change event for ${ uri . fsPath } ` , err ) ;
0 commit comments