@@ -7,7 +7,7 @@ import { createDebuggerProvider, activate as debuggerActivate, dispose as debugg
7
7
8
8
// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
9
9
// adapted from http://stackoverflow.com/q/5474008
10
- const PYTHON_REGEX = / ( ( [ ^ \d \W ] | [ \u00A0 - \uFFFF ] ) [ \w . \u00A0 - \uFFFF ] * ) | \. $ /
10
+ const PYTHON_REGEX = / ( ( [ ^ \W \d ] | [ \u00A0 - \uFFFF ] ) [ \w . \u00A0 - \uFFFF ] * ) | \. $ /
11
11
12
12
class PythonLanguageClient extends AutoLanguageClient {
13
13
activate ( ) {
@@ -23,8 +23,12 @@ class PythonLanguageClient extends AutoLanguageClient {
23
23
atom . notifications . addSuccess ( "ide-pyhon: atom-ide-base was installed and enabled..." )
24
24
} )
25
25
}
26
+ // Remove deprecated option
27
+ atom . config . unset ( "ide-python.pylsPath" )
28
+ debuggerActivate ( )
26
29
}
27
30
31
+ /* eslint-disable class-methods-use-this */
28
32
getGrammarScopes ( ) {
29
33
return [ "source.python" , "python" ]
30
34
}
@@ -41,13 +45,6 @@ class PythonLanguageClient extends AutoLanguageClient {
41
45
return "ide-python"
42
46
}
43
47
44
- activate ( ) {
45
- // Remove deprecated option
46
- atom . config . unset ( "ide-python.pylsPath" )
47
- super . activate ( )
48
- debuggerActivate ( )
49
- }
50
-
51
48
mapConfigurationObject ( configuration ) {
52
49
return {
53
50
pyls : {
@@ -57,20 +54,28 @@ class PythonLanguageClient extends AutoLanguageClient {
57
54
} ,
58
55
}
59
56
}
57
+ /* eslint-enable class-methods-use-this */
60
58
61
59
async startServerProcess ( projectPath ) {
62
60
const venvPath = ( await detectPipEnv ( projectPath ) ) || ( await detectVirtualEnv ( projectPath ) )
63
61
const pylsEnvironment = Object . assign ( { } , process . env )
64
62
if ( venvPath ) {
65
- pylsEnvironment [ "VIRTUAL_ENV" ] = venvPath
63
+ pylsEnvironment . VIRTUAL_ENV = venvPath
64
+ }
65
+
66
+ let pythonBin = atom . config . get ( "ide-python.python" ) || "python3"
67
+ if ( whichSync ( pythonBin , { nothrow : true } ) === null ) {
68
+ pythonBin = "python"
66
69
}
67
- this . python = replacePipEnvPathVar ( atom . config . get ( "ide-python.python" ) , venvPath )
70
+
71
+ this . python = replacePipEnvPathVar ( pythonBin , venvPath )
68
72
69
73
let pyls = atom . config . get ( "ide-python.pyls" ) || "pylsp"
70
74
// check if it exists
71
75
if ( whichSync ( pyls , { nothrow : true } ) === null ) {
72
76
pyls = "pyls"
73
77
}
78
+
74
79
const childProcess = super . spawn ( this . python , [ "-m" , pyls ] , {
75
80
cwd : projectPath ,
76
81
env : pylsEnvironment ,
@@ -80,7 +85,7 @@ class PythonLanguageClient extends AutoLanguageClient {
80
85
81
86
onSpawnError ( err ) {
82
87
const description =
83
- err . code == "ENOENT"
88
+ err . code === "ENOENT"
84
89
? `No Python interpreter found at \`${ this . python } \`.`
85
90
: `Could not spawn the Python interpreter \`${ this . python } \`.`
86
91
atom . notifications . addError ( "`ide-python` could not launch your Python runtime." , {
@@ -90,7 +95,7 @@ class PythonLanguageClient extends AutoLanguageClient {
90
95
}
91
96
92
97
onSpawnClose ( code , signal ) {
93
- if ( code !== 0 && signal == null ) {
98
+ if ( code !== 0 && signal === null ) {
94
99
atom . notifications . addError ( "Unable to start the Python language server." , {
95
100
dismissable : true ,
96
101
buttons : [
@@ -113,8 +118,10 @@ class PythonLanguageClient extends AutoLanguageClient {
113
118
}
114
119
}
115
120
116
- async getSuggestions ( request ) {
117
- if ( ! PYTHON_REGEX . test ( request . prefix ) ) return null
121
+ getSuggestions ( request ) {
122
+ if ( ! PYTHON_REGEX . test ( request . prefix ) ) {
123
+ return null
124
+ }
118
125
return super . getSuggestions ( request )
119
126
}
120
127
@@ -124,8 +131,8 @@ class PythonLanguageClient extends AutoLanguageClient {
124
131
}
125
132
126
133
createTimeoutPromise ( milliseconds ) {
127
- return new Promise ( ( resolve , reject ) => {
128
- let timeout = setTimeout ( ( ) => {
134
+ return new Promise ( ( resolve ) => {
135
+ const timeout = setTimeout ( ( ) => {
129
136
clearTimeout ( timeout )
130
137
this . logger . error ( `Server failed to shutdown in ${ milliseconds } ms, forcing termination` )
131
138
resolve ( )
0 commit comments