@@ -88,6 +88,7 @@ const configDocLink =
88
88
type CachedDocumentType = {
89
89
version : number ;
90
90
contents : CachedContent [ ] ;
91
+ size : number ;
91
92
} ;
92
93
93
94
function toPosition ( position : VscodePosition ) : IPosition {
@@ -498,17 +499,11 @@ export class MessageProcessor {
498
499
499
500
// As `contentChanges` is an array, and we just want the
500
501
// latest update to the text, grab the last entry from the array.
501
-
502
- // If it's a .js file, try parsing the contents to see if GraphQL queries
503
- // exist. If not found, delete from the cache.
504
502
const { contents } = await this . _parseAndCacheFile (
505
503
uri ,
506
504
project ,
507
505
contentChanges . at ( - 1 ) ! . text ,
508
506
) ;
509
- // // If it's a .graphql file, proceed normally and invalidate the cache.
510
- // await this._invalidateCache(textDocument, uri, contents);
511
-
512
507
const diagnostics : Diagnostic [ ] = [ ] ;
513
508
514
509
if ( project ?. extensions ?. languageService ?. enableValidation !== false ) {
@@ -718,7 +713,10 @@ export class MessageProcessor {
718
713
const contents = await this . _parser ( fileText , uri ) ;
719
714
const cachedDocument = this . _textDocumentCache . get ( uri ) ;
720
715
const version = cachedDocument ? cachedDocument . version ++ : 0 ;
721
- await this . _invalidateCache ( { uri, version } , uri , contents ) ;
716
+ await this . _invalidateCache (
717
+ { uri, version } ,
718
+ { contents, size : fileText . length } ,
719
+ ) ;
722
720
await this . _updateFragmentDefinition ( uri , contents ) ;
723
721
await this . _updateObjectTypeDefinition ( uri , contents , project ) ;
724
722
await this . _updateSchemaIfChanged ( project , uri ) ;
@@ -954,14 +952,13 @@ export class MessageProcessor {
954
952
955
953
const { textDocument } = params ;
956
954
const cachedDocument = this . _getCachedDocument ( textDocument . uri ) ;
957
- if ( ! cachedDocument ?. contents [ 0 ] ) {
955
+ if ( ! cachedDocument ?. contents ?. length ) {
958
956
return [ ] ;
959
957
}
960
958
961
959
if (
962
960
this . _settings . largeFileThreshold !== undefined &&
963
- this . _settings . largeFileThreshold <
964
- cachedDocument . contents [ 0 ] . query . length
961
+ this . _settings . largeFileThreshold < cachedDocument . size
965
962
) {
966
963
return [ ] ;
967
964
}
@@ -1015,7 +1012,13 @@ export class MessageProcessor {
1015
1012
documents . map ( async ( [ uri ] ) => {
1016
1013
const cachedDocument = this . _getCachedDocument ( uri ) ;
1017
1014
1018
- if ( ! cachedDocument ) {
1015
+ if ( ! cachedDocument ?. contents ?. length ) {
1016
+ return [ ] ;
1017
+ }
1018
+ if (
1019
+ this . _settings . largeFileThreshold !== undefined &&
1020
+ this . _settings . largeFileThreshold < cachedDocument . size
1021
+ ) {
1019
1022
return [ ] ;
1020
1023
}
1021
1024
const docSymbols = await this . _languageService . getDocumentSymbols (
@@ -1044,7 +1047,10 @@ export class MessageProcessor {
1044
1047
try {
1045
1048
const contents = await this . _parser ( text , uri ) ;
1046
1049
if ( contents . length > 0 ) {
1047
- await this . _invalidateCache ( { version, uri } , uri , contents ) ;
1050
+ await this . _invalidateCache (
1051
+ { version, uri } ,
1052
+ { contents, size : text . length } ,
1053
+ ) ;
1048
1054
await this . _updateObjectTypeDefinition ( uri , contents , project ) ;
1049
1055
}
1050
1056
} catch ( err ) {
@@ -1260,7 +1266,10 @@ export class MessageProcessor {
1260
1266
1261
1267
await this . _updateObjectTypeDefinition ( uri , contents ) ;
1262
1268
await this . _updateFragmentDefinition ( uri , contents ) ;
1263
- await this . _invalidateCache ( { version : 1 , uri } , uri , contents ) ;
1269
+ await this . _invalidateCache (
1270
+ { version : 1 , uri } ,
1271
+ { contents, size : document . rawSDL . length } ,
1272
+ ) ;
1264
1273
} ) ,
1265
1274
) ;
1266
1275
} catch ( err ) {
@@ -1369,27 +1378,20 @@ export class MessageProcessor {
1369
1378
}
1370
1379
private async _invalidateCache (
1371
1380
textDocument : VersionedTextDocumentIdentifier ,
1372
- uri : Uri ,
1373
- contents : CachedContent [ ] ,
1381
+ meta : Omit < CachedDocumentType , 'version' > ,
1374
1382
) : Promise < Map < string , CachedDocumentType > | null > {
1383
+ const { uri, version } = textDocument ;
1375
1384
if ( this . _textDocumentCache . has ( uri ) ) {
1376
1385
const cachedDocument = this . _textDocumentCache . get ( uri ) ;
1377
- if (
1378
- cachedDocument &&
1379
- textDocument ?. version &&
1380
- cachedDocument . version < textDocument . version
1381
- ) {
1386
+ if ( cachedDocument && version && cachedDocument . version < version ) {
1382
1387
// Current server capabilities specify the full sync of the contents.
1383
1388
// Therefore always overwrite the entire content.
1384
- return this . _textDocumentCache . set ( uri , {
1385
- version : textDocument . version ,
1386
- contents,
1387
- } ) ;
1389
+ return this . _textDocumentCache . set ( uri , { ...meta , version } ) ;
1388
1390
}
1389
1391
}
1390
1392
return this . _textDocumentCache . set ( uri , {
1391
- version : textDocument . version ?? 0 ,
1392
- contents ,
1393
+ ... meta ,
1394
+ version : version ?? 0 ,
1393
1395
} ) ;
1394
1396
}
1395
1397
}
0 commit comments