Skip to content

Commit 6097fc6

Browse files
author
Sander Ronde
committed
don't sync document when it goes from clean to dirty through an unsaved content change
1 parent cbb6e03 commit 6097fc6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

client/src/notificationSenders/documentManager.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export class DocumentManager implements Disposable {
2020
this._client = client;
2121
}
2222

23-
private _shouldSyncDocument(e: PartialDocument): boolean {
23+
private _shouldSyncDocument(
24+
e: PartialDocument,
25+
changes?: readonly vscode.TextDocumentContentChangeEvent[]
26+
): boolean {
2427
return (
2528
e.languageId === 'php' &&
2629
!e.isDirty &&
30+
(!changes || changes.length === 0) &&
2731
['file', 'vscode-vfs', 'git', 'vscode-remote'].includes(
2832
e.uri.scheme
2933
)
@@ -54,24 +58,26 @@ export class DocumentManager implements Disposable {
5458
};
5559
}
5660

57-
private async _onDocumentChange(e: vscode.TextDocument): Promise<void> {
58-
if (this._isConfigFile(e)) {
61+
private async _onDocumentChange(
62+
e: vscode.TextDocumentChangeEvent
63+
): Promise<void> {
64+
if (this._isConfigFile(e.document)) {
5965
debug('configChange', {
60-
filePath: sanitizeFilePath(e.uri.fsPath),
66+
filePath: sanitizeFilePath(e.document.uri.fsPath),
6167
});
6268
await this._client.sendNotification(watcherNotification, {
6369
operation: 'onConfigChange',
64-
file: this._toSendData(e),
70+
file: this._toSendData(e.document),
6571
});
6672
}
67-
if (this._shouldSyncDocument(e)) {
73+
if (this._shouldSyncDocument(e.document, e.contentChanges)) {
6874
debug('documentChange', {
6975
checking: true,
70-
filePath: sanitizeFilePath(e.uri.fsPath),
76+
filePath: sanitizeFilePath(e.document.uri.fsPath),
7177
});
7278
await this._client.sendNotification(watcherNotification, {
7379
operation: 'change',
74-
file: this._toSendData(e),
80+
file: this._toSendData(e.document),
7581
});
7682
}
7783
}
@@ -177,7 +183,7 @@ export class DocumentManager implements Disposable {
177183

178184
this._disposables.push(
179185
vscode.workspace.onDidChangeTextDocument((e) => {
180-
void this._onDocumentChange(e.document);
186+
void this._onDocumentChange(e);
181187
})
182188
);
183189

0 commit comments

Comments
 (0)