@@ -31,7 +31,10 @@ import {
31
31
WorkspaceEdit
32
32
} from 'vscode' ;
33
33
import {
34
+ ConfigurationParams ,
35
+ ConfigurationRequest ,
34
36
HandleDiagnosticsSignature ,
37
+ HandlerResult ,
35
38
Middleware ,
36
39
PrepareRenameSignature ,
37
40
ProvideCodeActionsSignature ,
@@ -51,13 +54,14 @@ import {
51
54
ProvideWorkspaceSymbolsSignature ,
52
55
ResolveCodeLensSignature ,
53
56
ResolveCompletionItemSignature ,
54
- ResolveDocumentLinkSignature
57
+ ResolveDocumentLinkSignature ,
58
+ ResponseError
55
59
} from 'vscode-languageclient' ;
56
60
57
61
import { ProvideDeclarationSignature } from 'vscode-languageclient/lib/declaration' ;
58
62
import { HiddenFilePrefix } from '../common/constants' ;
59
63
import { CollectLSRequestTiming , CollectNodeLSRequestTiming } from '../common/experimentGroups' ;
60
- import { IExperimentsManager , IPythonExtensionBanner } from '../common/types' ;
64
+ import { IConfigurationService , IExperimentsManager , IPythonExtensionBanner } from '../common/types' ;
61
65
import { StopWatch } from '../common/utils/stopWatch' ;
62
66
import { sendTelemetryEvent } from '../telemetry' ;
63
67
import { EventName } from '../telemetry/constants' ;
@@ -80,11 +84,47 @@ export class LanguageClientMiddleware implements Middleware {
80
84
public nextWindow : number = 0 ;
81
85
public eventCount : number = 0 ;
82
86
87
+ public workspace = {
88
+ // tslint:disable:no-any
89
+ configuration : (
90
+ params : ConfigurationParams ,
91
+ token : CancellationToken ,
92
+ next : ConfigurationRequest . HandlerSignature
93
+ ) : HandlerResult < any [ ] , void > => {
94
+ const result = next ( params , token ) ;
95
+
96
+ // For backwards compatibility, set python.pythonPath to the configured
97
+ // value as though it were in the user's settings.json file.
98
+ const addPythonPath = ( settings : any [ ] | ResponseError < void > ) => {
99
+ if ( settings instanceof ResponseError ) {
100
+ return settings ;
101
+ }
102
+
103
+ params . items . forEach ( ( item , i ) => {
104
+ if ( item . section === 'python' ) {
105
+ const uri = item . scopeUri ? Uri . parse ( item . scopeUri ) : undefined ;
106
+ settings [ i ] . pythonPath = this . configService . getSettings ( uri ) . pythonPath ;
107
+ }
108
+ } ) ;
109
+
110
+ return settings ;
111
+ } ;
112
+
113
+ if ( isThenable ( result ) ) {
114
+ return ( result as Thenable < any [ ] | ResponseError < void > > ) . then ( addPythonPath ) ;
115
+ }
116
+
117
+ return addPythonPath ( result ) ;
118
+ }
119
+ // tslint:enable:no-any
120
+ } ;
121
+
83
122
private connected = false ; // Default to not forwarding to VS code.
84
123
85
124
public constructor (
86
125
private readonly surveyBanner : IPythonExtensionBanner ,
87
126
experimentsManager : IExperimentsManager ,
127
+ private readonly configService : IConfigurationService ,
88
128
serverType : LanguageServerType ,
89
129
public readonly serverVersion ?: string
90
130
) {
@@ -413,8 +453,8 @@ function captureTelemetryForLSPMethod(method: string, debounceMilliseconds: numb
413
453
const result = originalMethod . apply ( this , args ) ;
414
454
415
455
// tslint:disable-next-line:no-unsafe-any
416
- if ( result && typeof result . then === 'function' ) {
417
- ( result as Thenable < void > ) . then ( ( ) => {
456
+ if ( result && isThenable < void > ( result ) ) {
457
+ result . then ( ( ) => {
418
458
sendTelemetryEvent ( eventName , stopWatch . elapsedTime , properties ) ;
419
459
} ) ;
420
460
} else {
@@ -427,3 +467,8 @@ function captureTelemetryForLSPMethod(method: string, debounceMilliseconds: numb
427
467
return descriptor ;
428
468
} ;
429
469
}
470
+
471
+ // tslint:disable-next-line: no-any
472
+ function isThenable < T > ( v : any ) : v is Thenable < T > {
473
+ return typeof v . then === 'function' ;
474
+ }
0 commit comments