microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.64k stars 28.67k forks source link

location returned from DefinitionProvider opens cell in new editor instead of notebook #96439

Closed weinand closed 4 years ago

weinand commented 4 years ago

Refs: #96282

The location returned from my fake definition provider (see below) did not open/focus on another cell in the notebook but opened the cell in a new editor:

2020-04-28_17-38-14 (1)

class MyDefinitionProvider implements vscode.DefinitionProvider {

    constructor(private container: ProjectContainer) {
    }

    provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Definition | vscode.DefinitionLink[]> {

        const project = this.container.lookupProject(document.uri);

        if (project.concatDoc) {
            const loc = new vscode.Location(document.uri, position);

            // map cell doc location to concat document position
            let pos = project.concatDoc.positionAt(loc);

            // fake "goto definition": assume definition on next line
            pos = new vscode.Position(pos.line+1, pos.character);

            // map concat document position back to cell doc location
            return project.concatDoc.locationAt(pos);
        }
        return undefined;
    }
}

Here is the full project: vscode-nodebooks.zip

jrieken commented 4 years ago

Seeing this error on the console

ERR Cannot register more than one working copy with the same resource vscode-notebook:/Users/jrieken/Code/_samples/devfest/foo/api.github-issues.: Error: Cannot register more than one working copy with the same resource vscode-notebook:/Users/jrieken/Code/_samples/devfest/foo/api.github-issues.
    at WorkingCopyService.registerWorkingCopy (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/workingCopy/common/workingCopyService.js:40:23)
    at new NotebookEditorInput (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebookEditorInput.js:104:56)
    at InstantiationService._createInstance (file:///Users/jrieken/Code/vscode/out/vs/platform/instantiation/common/instantiationService.js:88:20)
    at InstantiationService.createInstance (file:///Users/jrieken/Code/vscode/out/vs/platform/instantiation/common/instantiationService.js:59:31)
    at NotebookContribution.onEditorOpening (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebook.contribution.js:126:65)
    at Object.open (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebook.contribution.js:76:64)
    at EditorService.onGroupWillOpenEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:381:44)
    at file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:118:26
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at EditorGroupView.openEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/browser/parts/editor/editorGroupView.js:587:40)
    at EditorService.openEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:393:76)
    at MarkersView.openFileAtElement (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/markers/browser/markersView.js:187:40)
    at file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/markers/browser/markersView.js:334:26
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:112:37
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at TreeResourceNavigator.open (file:///Users/jrieken/Code/vscode/out/vs/platform/list/browser/listService.js:341:37)
    at TreeResourceNavigator.onSelection (file:///Users/jrieken/Code/vscode/out/vs/platform/list/browser/listService.js:337:22)
    at file:///Users/jrieken/Code/vscode/out/vs/platform/list/browser/listService.js:307:79
    at file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:650:34
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at Trait._set (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:747:35)
    at Trait.set (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:739:18)
    at MarkersTree.setSelection (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:1136:28)
    at TreeResourceNavigator.onFocus (file:///Users/jrieken/Code/vscode/out/vs/platform/list/browser/listService.js:313:29)
    at file:///Users/jrieken/Code/vscode/out/vs/platform/list/browser/listService.js:304:75
    at file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:650:34
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at Trait._set (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:747:35)
    at Trait.set (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:739:18)
    at TreeNodeList.setFocus (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:887:33)
    at TreeNodeListMouseController.onPointer (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/list/listWidget.js:472:23)
    at TreeNodeListMouseController.onPointer (file:///Users/jrieken/Code/vscode/out/vs/base/browser/ui/tree/abstractTree.js:839:19)
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:460:45)
    at file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:44:93
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at HTMLDivElement.fn (file:///Users/jrieken/Code/vscode/out/vs/base/browser/event.js:10:35)
log.js:144   ERR Cannot register more than one working copy with the same resource vscode-notebook:/Users/jrieken/Code/_samples/devfest/foo/api.github-issues.: Error: Cannot register more than one working copy with the same resource vscode-notebook:/Users/jrieken/Code/_samples/devfest/foo/api.github-issues.
    at WorkingCopyService.registerWorkingCopy (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/workingCopy/common/workingCopyService.js:40:23)
    at new NotebookEditorInput (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebookEditorInput.js:104:56)
    at InstantiationService._createInstance (file:///Users/jrieken/Code/vscode/out/vs/platform/instantiation/common/instantiationService.js:88:20)
    at InstantiationService.createInstance (file:///Users/jrieken/Code/vscode/out/vs/platform/instantiation/common/instantiationService.js:59:31)
    at NotebookContribution.onEditorOpening (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebook.contribution.js:126:65)
    at Object.open (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebook.contribution.js:76:64)
    at EditorService.onGroupWillOpenEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:381:44)
    at file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:118:26
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at EditorGroupView.openEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/browser/parts/editor/editorGroupView.js:587:40)
    at EditorService.openEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:393:76)
    at MarkersView.openFileAtElement (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/markers/browser/markersView.js:187:40)
    at file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/markers/browser/markersView.js:334:26
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:121:41
log.js:144   ERR Cannot register more than one working copy with the same resource vscode-notebook:/Users/jrieken/Code/_samples/devfest/foo/api.github-issues.: Error: Cannot register more than one working copy with the same resource vscode-notebook:/Users/jrieken/Code/_samples/devfest/foo/api.github-issues.
    at WorkingCopyService.registerWorkingCopy (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/workingCopy/common/workingCopyService.js:40:23)
    at new NotebookEditorInput (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebookEditorInput.js:104:56)
    at InstantiationService._createInstance (file:///Users/jrieken/Code/vscode/out/vs/platform/instantiation/common/instantiationService.js:88:20)
    at InstantiationService.createInstance (file:///Users/jrieken/Code/vscode/out/vs/platform/instantiation/common/instantiationService.js:59:31)
    at NotebookContribution.onEditorOpening (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebook.contribution.js:136:57)
    at Object.open (file:///Users/jrieken/Code/vscode/out/vs/workbench/contrib/notebook/browser/notebook.contribution.js:76:64)
    at EditorService.onGroupWillOpenEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:381:44)
    at file:///Users/jrieken/Code/vscode/out/vs/workbench/services/editor/browser/editorService.js:118:26
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:457:42)
    at EditorGroupView.openEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/browser/parts/editor/editorGroupView.js:587:40)
    at EditorGroupView.doCloseActiveEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/browser/parts/editor/editorGroupView.js:906:26)
    at EditorGroupView.doCloseEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/browser/parts/editor/editorGroupView.js:858:26)
    at EditorGroupView.closeEditor (file:///Users/jrieken/Code/vscode/out/vs/workbench/browser/parts/editor/editorGroupView.js:853:22)
    at async EditorCommandsContextActionRunner.run (file:///Users/jrieken/Code/vscode/out/vs/base/common/actions.js:107:32)
jrieken commented 4 years ago

/duplicate of https://github.com/microsoft/vscode/issues/96402

weinand commented 4 years ago

Works fine now and no errors show up in dev console