import { CancellationToken , DocumentHighlight , DocumentHighlightKind } from 'vscode-languageserver' ; import * as ParseTreeUtils from '../analyzer/parseTreeUtils' ; import { TypeEvaluator } from '../analyzer/typeEvaluatorTypes' ; import { throwIfCancellationRequested } from '../common/cancellationUtils' ; import { convertOffsetsToRange , convertPositionToOffset } from '../common/positionUtils' ; import { Position , TextRange } from '../common/textRange' ; import { ParseNodeType } from '../parser/parseNodes' ; import { ParseResults } from '../parser/parser' ; import { DocumentSymbolCollector } from './documentSymbolCollector' ; export class DocumentHighlightProvider { static getDocumentHighlight ( parseResults , position , evaluator , token ) { throwIfCancellationRequested ( token ) ; const offset = convertPositionToOffset ( position , parseResults . tokenizerOutput . lines ) ; if ( offset === undefined ) { return undefined ; } const node = ParseTreeUtils . findNodeByOffset ( parseResults . parseTree , offset ) ; if ( node === undefined ) { return undefined ; } if ( node . nodeType !== ParseNodeType . Name ) { return undefined ; } const results = DocumentSymbolCollector . collectFromNode ( node , evaluator , token , parseResults . parseTree , true ) ; return results . map ( ( r ) => ( { kind : r . node . nodeType === ParseNodeType . Name && ParseTreeUtils . isWriteAccess ( r . node ) ? DocumentHighlightKind . Write : DocumentHighlightKind . Read , range : convertOffsetsToRange ( r . range . start , TextRange . getEnd ( r . range ) , parseResults . tokenizerOutput . lines ) , } ) ) ; } }