2021年4月24日星期六

How to get current text/symbol when implementing Go To Definition

I'm working on my first vscode extension using Language Server Protocol, I need to get the text were the Right click -> Go to definition was triggered

enter image description here

My current onDefinition method receives only the textPosition

export default class DefinitionFinder extends Handler {      constructor(          protected connection: Connection,          private refManager: ReferenceManager)      {          super();            this.connection.onDefinition(async (textPosition) => {              return this.handleErrors(                  this.getDefinition(textPosition), undefined) as Promise<Definition>;          });      }        private async getDefinition(textPosition: TextDocumentPositionParams): Promise<Location[]> {      const text = "funABC";        // instead of hardcoded value I need to get the text/symbol       // that is going to be use to go to definition         return this.refManager.getDefinitionLocations(text);  }  

The TextDocumentPositionParams only contains the documentUri, line(number) and character(number)

Does that mean that on each call to onDefinition I need to open the document, go to the line and character and get the current word ?

export interface TextDocumentPositionParams {      /**       * The text document.       */      textDocument: TextDocumentIdentifier;      /**       * The position inside the text document.       */      position: Position;  }    export interface TextDocumentIdentifier {      /**       * The text document's uri. (string)       */      uri: DocumentUri;  }    export declare namespace Position {      /**       * Creates a new Position literal from the given line and character.       * @param line The position's line.       * @param character The position's character.       */  
https://stackoverflow.com/questions/67163731/how-to-get-current-text-symbol-when-implementing-go-to-definition April 19, 2021 at 10:17PM

没有评论:

发表评论