Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 98658

vscode how to automatically jump to proper definition

$
0
0
//extension.ts
export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "helloworld" is now active!');

    context.subscriptions.push(vscode.languages.registerDefinitionProvider(
        {language: "plsql"}, new GoDefinitionProvider() ));

}

class GoDefinitionProvider implements vscode.DefinitionProvider {
    public provideDefinition(
        document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken):
        Thenable<vscode.Definition>{
            return new Promise((resolve, reject) =>{
                let definitions:vscode.Definition = [];         
                for (let i = 0; i < document.lineCount; i++) {
                    let eachLine = document.lineAt(i).text.toLowerCase().trim();
                    if (eachLine.startsWith("cursor")) {                    
                        definitions.push({
                            uri: document.uri,
                            range: document.lineAt(i).range
                        });                     
                    }                   
                } 

                resolve(definitions);
            });

    }
}
// testing.txt
cursor a1 is
cursor a2 is
cursor a3 is
cursor a4 is
cursor a5 is
cursor a6 is
cursor a7 is
cursor a8 is
cursor a9 is

a1
a2
a3
a4
a5
a6
a7
a8
a9

for example, now we want to select "a4 " to jump to show definition, but the definition is auto jump to "cursor a9 is", not the proper one "cursor a4 is".

result image: https://i.imgur.com/RNAvWMN.png

how can I implement the auto jumping to the proper definition? Above is the source code of extension.ts for your reference.


Viewing all articles
Browse latest Browse all 98658

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>