@@ -17,6 +17,7 @@ import { URI } from '../../../../base/common/uri.js';
17
17
import { IContextKey , IContextKeyService , RawContextKey } from '../../../../platform/contextkey/common/contextkey.js' ;
18
18
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js' ;
19
19
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js' ;
20
+ import { ILogService } from '../../../../platform/log/common/log.js' ;
20
21
import { IActiveCodeEditor , ICodeEditor , isDiffEditor } from '../../../browser/editorBrowser.js' ;
21
22
import { EditorAction , EditorContributionInstantiation , IActionOptions , registerEditorAction , registerEditorContribution , registerModelAndPositionCommand } from '../../../browser/editorExtensions.js' ;
22
23
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js' ;
@@ -211,6 +212,7 @@ class WordHighlighter {
211
212
212
213
private readonly textModelService : ITextModelService ;
213
214
private readonly codeEditorService : ICodeEditorService ;
215
+ private readonly logService : ILogService ;
214
216
215
217
private occurrencesHighlight : string ;
216
218
@@ -237,13 +239,15 @@ class WordHighlighter {
237
239
contextKeyService : IContextKeyService ,
238
240
@ITextModelService textModelService : ITextModelService ,
239
241
@ICodeEditorService codeEditorService : ICodeEditorService ,
242
+ @ILogService logService : ILogService ,
240
243
) {
241
244
this . editor = editor ;
242
245
this . providers = providers ;
243
246
this . multiDocumentProviders = multiProviders ;
244
247
245
248
this . codeEditorService = codeEditorService ;
246
249
this . textModelService = textModelService ;
250
+ this . logService = logService ;
247
251
248
252
this . _hasWordHighlights = ctxHasWordHighlights . bindTo ( contextKeyService ) ;
249
253
this . _ignorePositionChangeEvent = false ;
@@ -685,17 +689,23 @@ class WordHighlighter {
685
689
if ( ! WordHighlighter . query || ! WordHighlighter . query . modelInfo ) {
686
690
return ;
687
691
}
692
+
688
693
const queryModelRef = await this . textModelService . createModelReference ( WordHighlighter . query . modelInfo . modelURI ) ;
689
- const queryModel = queryModelRef . object . textEditorModel ;
690
- this . workerRequest = this . computeWithModel ( queryModel , WordHighlighter . query . modelInfo . selection , otherModelsToHighlight ) ;
691
-
692
- this . workerRequest ?. result . then ( data => {
693
- if ( myRequestId === this . workerRequestTokenId ) {
694
- this . workerRequestCompleted = true ;
695
- this . workerRequestValue = data || [ ] ;
696
- this . _beginRenderDecorations ( ) ;
697
- }
698
- } , onUnexpectedError ) ;
694
+ try {
695
+ this . workerRequest = this . computeWithModel ( queryModelRef . object . textEditorModel , WordHighlighter . query . modelInfo . selection , otherModelsToHighlight ) ;
696
+ this . workerRequest ?. result . then ( data => {
697
+ if ( myRequestId === this . workerRequestTokenId ) {
698
+ this . workerRequestCompleted = true ;
699
+ this . workerRequestValue = data || [ ] ;
700
+ this . _beginRenderDecorations ( ) ;
701
+ }
702
+ } , onUnexpectedError ) ;
703
+ } catch ( e ) {
704
+ this . logService . error ( 'Unexpected error during occurrence request. Log: ' , e ) ;
705
+ } finally {
706
+ queryModelRef . dispose ( ) ;
707
+ }
708
+
699
709
} else if ( this . model . uri . scheme === Schemas . vscodeNotebookCell ) {
700
710
// new wordHighlighter coming from a different model, NOT the query model, need to create a textModel ref
701
711
@@ -709,16 +719,20 @@ class WordHighlighter {
709
719
}
710
720
711
721
const queryModelRef = await this . textModelService . createModelReference ( WordHighlighter . query . modelInfo . modelURI ) ;
712
- const queryModel = queryModelRef . object . textEditorModel ;
713
- this . workerRequest = this . computeWithModel ( queryModel , WordHighlighter . query . modelInfo . selection , [ this . model ] ) ;
714
-
715
- this . workerRequest ?. result . then ( data => {
716
- if ( myRequestId === this . workerRequestTokenId ) {
717
- this . workerRequestCompleted = true ;
718
- this . workerRequestValue = data || [ ] ;
719
- this . _beginRenderDecorations ( noDelay ) ;
720
- }
721
- } , onUnexpectedError ) ;
722
+ try {
723
+ this . workerRequest = this . computeWithModel ( queryModelRef . object . textEditorModel , WordHighlighter . query . modelInfo . selection , [ this . model ] ) ;
724
+ this . workerRequest ?. result . then ( data => {
725
+ if ( myRequestId === this . workerRequestTokenId ) {
726
+ this . workerRequestCompleted = true ;
727
+ this . workerRequestValue = data || [ ] ;
728
+ this . _beginRenderDecorations ( noDelay ) ;
729
+ }
730
+ } , onUnexpectedError ) ;
731
+ } catch ( e ) {
732
+ this . logService . error ( 'Unexpected error during occurrence request. Log: ' , e ) ;
733
+ } finally {
734
+ queryModelRef . dispose ( ) ;
735
+ }
722
736
}
723
737
}
724
738
@@ -814,12 +828,13 @@ export class WordHighlighterContribution extends Disposable implements IEditorCo
814
828
@ILanguageFeaturesService languageFeaturesService : ILanguageFeaturesService ,
815
829
@ICodeEditorService codeEditorService : ICodeEditorService ,
816
830
@ITextModelService textModelService : ITextModelService ,
831
+ @ILogService logService : ILogService ,
817
832
) {
818
833
super ( ) ;
819
834
this . _wordHighlighter = null ;
820
835
const createWordHighlighterIfPossible = ( ) => {
821
836
if ( editor . hasModel ( ) && ! editor . getModel ( ) . isTooLargeForTokenization ( ) ) {
822
- this . _wordHighlighter = new WordHighlighter ( editor , languageFeaturesService . documentHighlightProvider , languageFeaturesService . multiDocumentHighlightProvider , contextKeyService , textModelService , codeEditorService ) ;
837
+ this . _wordHighlighter = new WordHighlighter ( editor , languageFeaturesService . documentHighlightProvider , languageFeaturesService . multiDocumentHighlightProvider , contextKeyService , textModelService , codeEditorService , logService ) ;
823
838
}
824
839
} ;
825
840
this . _register ( editor . onDidChangeModel ( ( e ) => {
0 commit comments