@@ -24,6 +24,8 @@ import {
2424 Severity ,
2525 type Workspace ,
2626 CompletionKind ,
27+ DocumentHighlight ,
28+ DocumentHighlightKind ,
2729} from "ty_wasm" ;
2830import { FileId , ReadonlyFiles } from "../Playground" ;
2931import { isPythonFile } from "./Files" ;
@@ -156,7 +158,8 @@ class PlaygroundServer
156158 languages . CompletionItemProvider ,
157159 languages . DocumentSemanticTokensProvider ,
158160 languages . DocumentRangeSemanticTokensProvider ,
159- languages . SignatureHelpProvider
161+ languages . SignatureHelpProvider ,
162+ languages . DocumentHighlightProvider
160163{
161164 private typeDefinitionProviderDisposable : IDisposable ;
162165 private declarationProviderDisposable : IDisposable ;
@@ -170,6 +173,7 @@ class PlaygroundServer
170173 private semanticTokensDisposable : IDisposable ;
171174 private rangeSemanticTokensDisposable : IDisposable ;
172175 private signatureHelpDisposable : IDisposable ;
176+ private documentHighlightDisposable : IDisposable ;
173177
174178 constructor (
175179 private monaco : Monaco ,
@@ -207,6 +211,8 @@ class PlaygroundServer
207211 monaco . languages . registerDocumentFormattingEditProvider ( "python" , this ) ;
208212 this . signatureHelpDisposable =
209213 monaco . languages . registerSignatureHelpProvider ( "python" , this ) ;
214+ this . documentHighlightDisposable =
215+ monaco . languages . registerDocumentHighlightProvider ( "python" , this ) ;
210216 }
211217
212218 triggerCharacters : string [ ] = [ "." ] ;
@@ -365,6 +371,36 @@ class PlaygroundServer
365371 } ;
366372 }
367373
374+ provideDocumentHighlights (
375+ model : editor . ITextModel ,
376+ position : Position ,
377+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
378+ _token : CancellationToken ,
379+ ) : languages . ProviderResult < languages . DocumentHighlight [ ] > {
380+ const workspace = this . props . workspace ;
381+ const selectedFile = this . props . files . selected ;
382+
383+ if ( selectedFile == null ) {
384+ return ;
385+ }
386+
387+ const selectedHandle = this . props . files . handles [ selectedFile ] ;
388+
389+ if ( selectedHandle == null ) {
390+ return ;
391+ }
392+
393+ const highlights = workspace . documentHighlights (
394+ selectedHandle ,
395+ new TyPosition ( position . lineNumber , position . column ) ,
396+ ) ;
397+
398+ return highlights . map ( ( highlight : DocumentHighlight ) => ( {
399+ range : tyRangeToMonacoRange ( highlight . range ) ,
400+ kind : mapDocumentHighlightKind ( highlight . kind ) ,
401+ } ) ) ;
402+ }
403+
368404 provideInlayHints (
369405 _model : editor . ITextModel ,
370406 range : Range ,
@@ -707,6 +743,7 @@ class PlaygroundServer
707743 this . semanticTokensDisposable . dispose ( ) ;
708744 this . completionDisposable . dispose ( ) ;
709745 this . signatureHelpDisposable . dispose ( ) ;
746+ this . documentHighlightDisposable . dispose ( ) ;
710747 }
711748}
712749
@@ -836,3 +873,18 @@ function mapCompletionKind(kind: CompletionKind): CompletionItemKind {
836873 return CompletionItemKind . TypeParameter ;
837874 }
838875}
876+
877+ function mapDocumentHighlightKind (
878+ kind : DocumentHighlightKind ,
879+ ) : languages . DocumentHighlightKind {
880+ switch ( kind ) {
881+ case DocumentHighlightKind . Text :
882+ return languages . DocumentHighlightKind . Text ;
883+ case DocumentHighlightKind . Read :
884+ return languages . DocumentHighlightKind . Read ;
885+ case DocumentHighlightKind . Write :
886+ return languages . DocumentHighlightKind . Write ;
887+ default :
888+ return languages . DocumentHighlightKind . Text ;
889+ }
890+ }
0 commit comments