Skip to content

Commit 5d3d2ae

Browse files
committed
Check if prefix is valid identifier before requesting completion
1 parent 674d592 commit 5d3d2ae

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const cp = require("child_process");
22
const { shell } = require("electron");
33
const { AutoLanguageClient } = require("atom-languageclient");
44

5+
// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
6+
// adapted from http://stackoverflow.com/q/5474008
7+
const PYTHON_REGEX = /([^\d\W]|[\u00A0-\uFFFF])[\w.\u00A0-\uFFFF]*$/;
8+
59
class PythonLanguageClient extends AutoLanguageClient {
610
getGrammarScopes() {
711
return ["source.python"];
@@ -40,6 +44,11 @@ class PythonLanguageClient extends AutoLanguageClient {
4044
);
4145
return childProcess;
4246
}
47+
48+
async getSuggestions(request) {
49+
if (!PYTHON_REGEX.test(request.prefix)) return null;
50+
return super.getSuggestions(request);
51+
}
4352
}
4453

4554
module.exports = new PythonLanguageClient();

0 commit comments

Comments
 (0)