@@ -15,8 +15,14 @@ export interface ProjectContextChangeEvent {
15
15
languageId : string ;
16
16
uri : vscode . Uri ;
17
17
context : VSProjectContext ;
18
+ isVerified : boolean ;
18
19
}
19
20
21
+ const VerificationDelay = 2 * 1000 ;
22
+
23
+ let _verifyTimeout : NodeJS . Timeout | undefined ;
24
+ let _documentUriToVerify : vscode . Uri | undefined ;
25
+
20
26
export class ProjectContextService {
21
27
private readonly _contextChangeEmitter = new vscode . EventEmitter < ProjectContextChangeEvent > ( ) ;
22
28
private _source = new vscode . CancellationTokenSource ( ) ;
@@ -47,7 +53,7 @@ export class ProjectContextService {
47
53
public async refresh ( ) {
48
54
const textEditor = vscode . window . activeTextEditor ;
49
55
const languageId = textEditor ?. document ?. languageId ;
50
- if ( languageId !== 'csharp' && languageId !== 'aspnetcorerazor' ) {
56
+ if ( languageId !== 'csharp' ) {
51
57
return ;
52
58
}
53
59
@@ -57,19 +63,55 @@ export class ProjectContextService {
57
63
58
64
const uri = textEditor ! . document . uri ;
59
65
66
+ // Whether we have refreshed the active document's project context.
67
+ let isVerifyPass = false ;
68
+
69
+ if ( _verifyTimeout ) {
70
+ // If we have changed active document then do not verify the previous one.
71
+ clearTimeout ( _verifyTimeout ) ;
72
+ _verifyTimeout = undefined ;
73
+ }
74
+
75
+ if ( _documentUriToVerify ) {
76
+ if ( uri . toString ( ) === _documentUriToVerify . toString ( ) ) {
77
+ // We have rerequested project contexts for the active document
78
+ // and we can now notify if the document isn't part of the workspace.
79
+ isVerifyPass = true ;
80
+ }
81
+
82
+ _documentUriToVerify = undefined ;
83
+ }
84
+
60
85
if ( ! this . _languageServer . isRunning ( ) ) {
61
- this . _contextChangeEmitter . fire ( { languageId, uri, context : this . _emptyProjectContext } ) ;
86
+ this . _contextChangeEmitter . fire ( { languageId, uri, context : this . _emptyProjectContext , isVerified : false } ) ;
62
87
return ;
63
88
}
64
89
65
90
const contextList = await this . getProjectContexts ( uri , this . _source . token ) ;
66
91
if ( ! contextList ) {
67
- this . _contextChangeEmitter . fire ( { languageId, uri, context : this . _emptyProjectContext } ) ;
92
+ this . _contextChangeEmitter . fire ( { languageId, uri, context : this . _emptyProjectContext , isVerified : false } ) ;
68
93
return ;
69
94
}
70
95
71
96
const context = contextList . _vs_projectContexts [ contextList . _vs_defaultIndex ] ;
72
- this . _contextChangeEmitter . fire ( { languageId, uri, context } ) ;
97
+ const isVerified = ! context . _vs_is_miscellaneous || isVerifyPass ;
98
+ this . _contextChangeEmitter . fire ( { languageId, uri, context, isVerified } ) ;
99
+
100
+ if ( context . _vs_is_miscellaneous && ! isVerifyPass ) {
101
+ // Request the active project context be refreshed but delay the request to give
102
+ // time for the project system to update with new files.
103
+ _verifyTimeout = setTimeout ( ( ) => {
104
+ _verifyTimeout = undefined ;
105
+ _documentUriToVerify = uri ;
106
+
107
+ // Trigger a refresh, but don't block on refresh completing.
108
+ this . refresh ( ) . catch ( ( e ) => {
109
+ throw new Error ( `Error refreshing project context status ${ e } ` ) ;
110
+ } ) ;
111
+ } , VerificationDelay ) ;
112
+
113
+ return ;
114
+ }
73
115
}
74
116
75
117
private async getProjectContexts (
0 commit comments