@@ -92,11 +92,20 @@ export default class BashServer {
92
92
* care about.
93
93
*/
94
94
public register ( connection : LSP . Connection ) : void {
95
+ const hasConfigurationCapability = ! ! this . clientCapabilities ?. workspace ?. configuration
96
+
97
+ let currentDocument : TextDocument | null = null
98
+ let initialized = false // Whether the client finished initializing
99
+
95
100
this . documents . listen ( this . connection )
96
- this . documents . onDidChangeContent ( async ( { document } ) => {
101
+
102
+ this . documents . onDidChangeContent ( ( { document } ) => {
97
103
// The content of a text document has changed. This event is emitted
98
104
// when the text document first opened or when its content has changed.
99
- await this . onDocumentContentChange ( document )
105
+ currentDocument = document
106
+ if ( initialized ) {
107
+ this . analyzeAndLintDocument ( document )
108
+ }
100
109
} )
101
110
102
111
this . documents . onDidClose ( ( event ) => {
@@ -114,9 +123,6 @@ export default class BashServer {
114
123
connection . onCompletionResolve ( this . onCompletionResolve . bind ( this ) )
115
124
connection . onCodeAction ( this . onCodeAction . bind ( this ) )
116
125
117
- const hasConfigurationCapability = ! ! this . clientCapabilities ?. workspace ?. configuration
118
- let initialized = false
119
-
120
126
/**
121
127
* The initialized notification is sent from the client to the server after
122
128
* the client received the result of the initialize request but before the
@@ -162,6 +168,11 @@ export default class BashServer {
162
168
}
163
169
164
170
initialized = true
171
+ if ( currentDocument ) {
172
+ // If we already have a document, analyze it now that we're initialized
173
+ // and the linter is ready.
174
+ this . analyzeAndLintDocument ( currentDocument )
175
+ }
165
176
166
177
// NOTE: we do not block the server initialization on this background analysis.
167
178
return { backgroundAnalysisCompleted : this . startBackgroundAnalysis ( ) }
@@ -173,7 +184,7 @@ export default class BashServer {
173
184
if ( configChanged && initialized ) {
174
185
this . connection . console . log ( 'Configuration changed' )
175
186
this . startBackgroundAnalysis ( )
176
- // TODO: we should trigger the linter again
187
+ // TODO: we should trigger the linter again for the current file
177
188
}
178
189
} )
179
190
@@ -211,10 +222,9 @@ export default class BashServer {
211
222
}
212
223
213
224
/**
214
- * The content of a text document has changed. This event is emitted
215
- * when the text document first opened or when its content has changed.
225
+ * Analyze and lint the given document.
216
226
*/
217
- public async onDocumentContentChange ( document : TextDocument ) {
227
+ public async analyzeAndLintDocument ( document : TextDocument ) {
218
228
const { uri } = document
219
229
220
230
let diagnostics : LSP . Diagnostic [ ] = [ ]
@@ -399,7 +409,6 @@ export default class BashServer {
399
409
) {
400
410
const shellDocumentation = await getShellDocumentation ( { word } )
401
411
if ( shellDocumentation ) {
402
- // eslint-disable-next-line no-console
403
412
return { contents : getMarkdownContent ( shellDocumentation ) }
404
413
}
405
414
} else {
0 commit comments