Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 9f4a6e4

Browse files
committed
Handle editor contents changing
If the editor contents have been changed since the lint was triggered the results returned are no longer valid. If this has happend tell Linter not to update the current message set for the provider as any current messages will have "followed" the text if possible.
1 parent 17cd211 commit 9f4a6e4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/main.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default {
6363
scope: 'file',
6464
lintOnFly: false,
6565
grammarScopes: ['source.c', 'source.cpp', 'source.objc', 'source.objcpp'],
66-
lint: (editor) => {
66+
lint: async (editor) => {
6767
if (helpers === null) {
6868
helpers = require('atom-linter');
6969
}
@@ -72,6 +72,7 @@ export default {
7272
}
7373

7474
const filePath = editor.getPath();
75+
const fileText = editor.getText();
7576

7677
const args = [
7778
'-fsyntax-only',
@@ -136,9 +137,16 @@ export default {
136137
allowEmptyStderr: true,
137138
};
138139

139-
return helpers.exec(this.execPath, args, execOpts).then(output =>
140-
helpers.parse(output, regex),
141-
);
140+
const output = await helpers.exec(this.execPath, args, execOpts);
141+
142+
if (editor.getText() !== fileText) {
143+
// Editor contents have changed, tell Linter not to update results
144+
// eslint-disable-next-line no-console
145+
console.warn('linter-clang: Editor contents changed, not updating results');
146+
return null;
147+
}
148+
149+
return helpers.parse(output, regex);
142150
},
143151
};
144152
},

0 commit comments

Comments
 (0)