@@ -48,19 +48,15 @@ function getAST(uri: string): AST {
48
48
let context = contextCache . get ( uri ) ;
49
49
if ( ! context ) {
50
50
context = DEFAULT_CONTEXT ;
51
- contextCache . set ( uri , DEFAULT_CONTEXT ) ;
52
51
console . log ( `No context found for ${ uri } , using default context ${ JSON . stringify ( DEFAULT_CONTEXT ) } ` ) ;
53
52
}
54
- // console.log(`Creating AST for ${uri} with context ${JSON.stringify(context)}`);
55
53
56
- // const ast = new AST(documents.get(uri)!.getText(), context, uri, 4);
57
54
const ast = new AST ( documents . get ( uri ) ! . getText ( ) , context , uri ) ;
58
55
astCache . set ( uri , ast ) ;
59
56
return ast ;
60
57
}
61
58
62
59
connection . onInitialize ( ( params : InitializeParams ) => {
63
- connection . console . log ( 'LSP INIT' ) ;
64
60
let capabilities = params . capabilities ;
65
61
66
62
// Does the client support the `workspace/configuration` request?
@@ -213,25 +209,16 @@ connection.onHover((params: HoverParams): Hover | null => {
213
209
} )
214
210
215
211
connection . onRequest ( "source/publishInfo" , ( info : { [ uri : string ] : Context } ) => {
216
- connection . console . log ( "Info" ) ;
217
- connection . console . log ( JSON . stringify ( info ) ) ;
218
-
219
212
for ( const [ uri , context ] of Object . entries ( info ) ) {
220
- const document = documents . get ( uri ) ;
221
- if ( document ) {
222
- let oldContext = contextCache . get ( uri ) ;
223
- if ( ! oldContext ) {
224
- oldContext = context ;
225
- contextCache . set ( uri , context ) ;
226
- astCache . delete ( uri ) ;
213
+ const oldContext = contextCache . get ( uri ) ;
214
+ if ( ! oldContext || context . chapter !== oldContext . chapter || context . prepend !== oldContext . prepend ) {
215
+ // Context has been added or changed for this URI
216
+ contextCache . set ( uri , context ) ;
217
+ astCache . delete ( uri ) ;
218
+ const document = documents . get ( uri ) ;
219
+ if ( document ) {
227
220
validateTextDocument ( document )
228
221
}
229
- // Check if context changed
230
- else if ( context . chapter !== oldContext . chapter || context . prepend !== oldContext . prepend ) {
231
- contextCache . set ( uri , context ) ;
232
- astCache . delete ( uri ) ;
233
- validateTextDocument ( document ) ;
234
- }
235
222
}
236
223
}
237
224
@@ -242,4 +229,4 @@ connection.onRequest("source/publishInfo", (info: { [uri: string]: Context }) =>
242
229
documents . listen ( connection ) ;
243
230
244
231
// Listen on the connection
245
- connection . listen ( ) ;
232
+ connection . listen ( ) ;
0 commit comments