11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33import { inject , injectable } from 'inversify' ;
4+ import * as path from 'path' ;
5+ import { WorkspaceFolder } from 'vscode' ;
6+ import { IWorkspaceService } from '../../common/application/types' ;
7+ import { IConfigurationService , Resource } from '../../common/types' ;
48
59import { IEnvironmentVariablesProvider } from '../../common/variables/types' ;
10+ import { PythonEnvironment } from '../../pythonEnvironments/info' ;
611import { LanguageServerAnalysisOptionsWithEnv } from '../common/analysisOptions' ;
712import { ILanguageServerOutputChannel } from '../types' ;
813
914/* eslint-disable @typescript-eslint/explicit-module-boundary-types, class-methods-use-this */
1015
1116@injectable ( )
1217export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOptionsWithEnv {
13- // eslint-disable-next-line @typescript-eslint/no-useless-constructor
18+ private resource : Resource | undefined ;
19+
1420 constructor (
1521 @inject ( IEnvironmentVariablesProvider ) envVarsProvider : IEnvironmentVariablesProvider ,
1622 @inject ( ILanguageServerOutputChannel ) lsOutputChannel : ILanguageServerOutputChannel ,
23+ @inject ( IConfigurationService ) private readonly configurationService : IConfigurationService ,
24+ @inject ( IWorkspaceService ) private readonly workspace : IWorkspaceService ,
1725 ) {
1826 super ( envVarsProvider , lsOutputChannel ) ;
27+ this . resource = undefined ;
28+ }
29+
30+ public async initialize ( resource : Resource , interpreter : PythonEnvironment | undefined ) {
31+ this . resource = resource ;
32+ return super . initialize ( resource , interpreter ) ;
33+ }
34+
35+ protected getWorkspaceFolder ( ) : WorkspaceFolder | undefined {
36+ return this . workspace . getWorkspaceFolder ( this . resource ) ;
1937 }
2038
2139 protected async getInitializationOptions ( ) {
40+ const pythonSettings = this . configurationService . getSettings ( this . resource ) ;
41+ const workspacePath = this . getWorkspaceFolder ( ) ?. uri . fsPath ;
42+ const extraPaths = pythonSettings . autoComplete
43+ ? pythonSettings . autoComplete . extraPaths . map ( ( extraPath ) => {
44+ if ( path . isAbsolute ( extraPath ) ) {
45+ return extraPath ;
46+ }
47+ return workspacePath ? path . join ( workspacePath , extraPath ) : '' ;
48+ } )
49+ : [ ] ;
50+
51+ if ( workspacePath ) {
52+ extraPaths . unshift ( workspacePath ) ;
53+ }
54+
55+ const distinctExtraPaths = extraPaths
56+ . filter ( ( value ) => value . length > 0 )
57+ . filter ( ( value , index , self ) => self . indexOf ( value ) === index ) ;
58+
2259 return {
2360 markupKindPreferred : 'markdown' ,
2461 completion : {
@@ -31,6 +68,9 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
3168 didSave : true ,
3269 didChange : true ,
3370 } ,
71+ workspace : {
72+ extraPaths : distinctExtraPaths ,
73+ } ,
3474 } ;
3575 }
3676}
0 commit comments