Skip to content

Duplicated definition references found when Go to Definition #63895

@ayqy

Description

@ayqy

Current Behavior:

External extensions contributed definitions are duplicated with build-in extensions (eg. typescript related extensions), and there is no way for external extensions to know whether other definitions exist or not.

image

Expected Feature:

  • Provide an option for vscode.languages.registerDefinitionProvider to avoid such conflicts with build-in or other external DefinitionProviders.

  • Alternatively, provide an API to get build-in or all other definitions, just lift conflicts to external extensions.

Steps to Reproduce:

  1. Clone the test-def repo
  2. Open test-def folder with VS Code, and then Start Debugging
  3. Open test-def/src folder with [Extension Development Host], and open test-def/src/extensions.ts
  4. import * as test from './test/index'; Go to Definition of ./test/index
  5. Two definitions found

Further More:

The exactly same definitions will be filtered, so I tried to provide the same definition with build-in result, and failed as well:

public provideDefinition(
    document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken):
    Thenable<vscode.Location> {
        console.log('trigger GoDefinitionProvider at ' + Date.now());
    return new Promise((resolve) => {

        // ... Do some stuff to find definitions 

        let file = path.join(__dirname, '../src/test/index.ts');
        console.log('resolve some thing ' + file);

        vscode.workspace.openTextDocument(file).then(doc => {
            // default range
            // {startLineNumber: 13, startColumn: 1, endLineNumber: 22, endColumn: 29}
            let range = doc.validateRange(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(99999, 99999)));
            
            //!!! Change startPosition.line to 12 will do the trick,
            // but there's no way to know other definitions exactly.
            // let range = doc.validateRange(new vscode.Range(new vscode.Position(12, 0), new vscode.Position(99999, 99999)));


            console.log(range);
            resolve(new vscode.Location(
                vscode.Uri.file(file),
                range
            ));
        });
    })
}

Metadata

Metadata

Assignees

Labels

*as-designedDescribed behavior is as designedinfo-neededIssue requires more information from poster

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions