@@ -7,7 +7,7 @@ import { createDebuggerProvider, activate as debuggerActivate, dispose as debugg
77
88// Ref: https://github.com/nteract/hydrogen/blob/master/lib/autocomplete-provider.js#L33
99// 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 ] * ) | \. $ /
1111
1212class PythonLanguageClient extends AutoLanguageClient {
1313 activate ( ) {
@@ -23,8 +23,12 @@ class PythonLanguageClient extends AutoLanguageClient {
2323 atom . notifications . addSuccess ( "ide-pyhon: atom-ide-base was installed and enabled..." )
2424 } )
2525 }
26+ // Remove deprecated option
27+ atom . config . unset ( "ide-python.pylsPath" )
28+ debuggerActivate ( )
2629 }
2730
31+ /* eslint-disable class-methods-use-this */
2832 getGrammarScopes ( ) {
2933 return [ "source.python" , "python" ]
3034 }
@@ -41,13 +45,6 @@ class PythonLanguageClient extends AutoLanguageClient {
4145 return "ide-python"
4246 }
4347
44- activate ( ) {
45- // Remove deprecated option
46- atom . config . unset ( "ide-python.pylsPath" )
47- super . activate ( )
48- debuggerActivate ( )
49- }
50-
5148 mapConfigurationObject ( configuration ) {
5249 return {
5350 pyls : {
@@ -57,20 +54,28 @@ class PythonLanguageClient extends AutoLanguageClient {
5754 } ,
5855 }
5956 }
57+ /* eslint-enable class-methods-use-this */
6058
6159 async startServerProcess ( projectPath ) {
6260 const venvPath = ( await detectPipEnv ( projectPath ) ) || ( await detectVirtualEnv ( projectPath ) )
6361 const pylsEnvironment = Object . assign ( { } , process . env )
6462 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"
6669 }
67- this . python = replacePipEnvPathVar ( atom . config . get ( "ide-python.python" ) , venvPath )
70+
71+ this . python = replacePipEnvPathVar ( pythonBin , venvPath )
6872
6973 let pyls = atom . config . get ( "ide-python.pyls" ) || "pylsp"
7074 // check if it exists
7175 if ( whichSync ( pyls , { nothrow : true } ) === null ) {
7276 pyls = "pyls"
7377 }
78+
7479 const childProcess = super . spawn ( this . python , [ "-m" , pyls ] , {
7580 cwd : projectPath ,
7681 env : pylsEnvironment ,
@@ -80,7 +85,7 @@ class PythonLanguageClient extends AutoLanguageClient {
8085
8186 onSpawnError ( err ) {
8287 const description =
83- err . code == "ENOENT"
88+ err . code === "ENOENT"
8489 ? `No Python interpreter found at \`${ this . python } \`.`
8590 : `Could not spawn the Python interpreter \`${ this . python } \`.`
8691 atom . notifications . addError ( "`ide-python` could not launch your Python runtime." , {
@@ -90,7 +95,7 @@ class PythonLanguageClient extends AutoLanguageClient {
9095 }
9196
9297 onSpawnClose ( code , signal ) {
93- if ( code !== 0 && signal == null ) {
98+ if ( code !== 0 && signal === null ) {
9499 atom . notifications . addError ( "Unable to start the Python language server." , {
95100 dismissable : true ,
96101 buttons : [
@@ -113,8 +118,10 @@ class PythonLanguageClient extends AutoLanguageClient {
113118 }
114119 }
115120
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+ }
118125 return super . getSuggestions ( request )
119126 }
120127
@@ -124,8 +131,8 @@ class PythonLanguageClient extends AutoLanguageClient {
124131 }
125132
126133 createTimeoutPromise ( milliseconds ) {
127- return new Promise ( ( resolve , reject ) => {
128- let timeout = setTimeout ( ( ) => {
134+ return new Promise ( ( resolve ) => {
135+ const timeout = setTimeout ( ( ) => {
129136 clearTimeout ( timeout )
130137 this . logger . error ( `Server failed to shutdown in ${ milliseconds } ms, forcing termination` )
131138 resolve ( )
0 commit comments