@@ -48,19 +48,15 @@ function getAST(uri: string): AST {
4848 let context = contextCache . get ( uri ) ;
4949 if ( ! context ) {
5050 context = DEFAULT_CONTEXT ;
51- contextCache . set ( uri , DEFAULT_CONTEXT ) ;
5251 console . log ( `No context found for ${ uri } , using default context ${ JSON . stringify ( DEFAULT_CONTEXT ) } ` ) ;
5352 }
54- // console.log(`Creating AST for ${uri} with context ${JSON.stringify(context)}`);
5553
56- // const ast = new AST(documents.get(uri)!.getText(), context, uri, 4);
5754 const ast = new AST ( documents . get ( uri ) ! . getText ( ) , context , uri ) ;
5855 astCache . set ( uri , ast ) ;
5956 return ast ;
6057}
6158
6259connection . onInitialize ( ( params : InitializeParams ) => {
63- connection . console . log ( 'LSP INIT' ) ;
6460 let capabilities = params . capabilities ;
6561
6662 // Does the client support the `workspace/configuration` request?
@@ -213,25 +209,16 @@ connection.onHover((params: HoverParams): Hover | null => {
213209} )
214210
215211connection . onRequest ( "source/publishInfo" , ( info : { [ uri : string ] : Context } ) => {
216- connection . console . log ( "Info" ) ;
217- connection . console . log ( JSON . stringify ( info ) ) ;
218-
219212 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 ) {
227220 validateTextDocument ( document )
228221 }
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- }
235222 }
236223 }
237224
@@ -242,4 +229,4 @@ connection.onRequest("source/publishInfo", (info: { [uri: string]: Context }) =>
242229documents . listen ( connection ) ;
243230
244231// Listen on the connection
245- connection . listen ( ) ;
232+ connection . listen ( ) ;
0 commit comments