Change:
<!-- Do Not Delete This! bugreporttemplate --<!-- Please read our Rules of Conduct: --<!-- Read our guide about submitting issues: --<!-- Search existing issues to avoid creating duplicates. --<!-- Test using the latest Insiders build to see if your issue has already been fixed: --<!-- Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. --<!-- Launch with to check. --Does this issue occur when all extensions are disabled?: Yes <!-- If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. --<!-- Issues caused by an extension need to be reported directly to the extension publisher. The 'Help Report Issue' dialog can assist with this. --- VS Code Versions: (@ ), (@ ), (@ ) OS: Win11 x64 (Windows_NT x64 10.0.) <br/Description: "Find all References" shows found results in the "References" side bar. Clicking on a result opens corresponding location. But if result is inside an untitled file, it doesn't go to the location inside that untitled doc, but instead opens a new (empty) untitled doc. Steps to Reproduce: new untitled file () typescript as language ( -) some code to find references: -Click on and select Side Bar should pop up and show one result ( in untitled file) on found result Expected: should show existing untitled file and move cursor to Actual: opens new (empty) untitled file ! Note: Issue isn't just with but with all results that are shown inside References Side Bar. For example same behaviour occurs for too Note: does work and moves cursor to the correct location Note: This isn't a TypeScript issue, but happens for all References results in untitled files, independent of References source. For example same issue with References in Markdown: ! Or with Powershell Extension: ! Note: Issue doesn't exist on web version. In Web version it moves the cursor to the correct location in the correct untitled document and doesn't create a new one. <br/Additional strange behaviour with opened untitled doc from result: If you use in the newly opened untitled file (from previous result), cursor moves to the correct location. And in old untitled doc now opens in new (but now existing) untitled doc ! To reproduce: open new untitled doc () Set language to Typescript and write: Right Click & on value -References Side Bar opens with one result Click on result -new untitled doc opens Set language to markdown and write: on title and click on result -cursor should move to heading (-correct) Switch to prev untitled doc (with Typescript code) on value and click on result -goes to other existing untitled doc (with markdown)
This seems to be a problem with the command. There is some for untitled-uris which forces a new untitled file
<!-- AUTHORVERIFICATIONREQUEST --This bug has been fixed in the latest release of ! you can help us out by commenting if things are now working as expected. If things still don't seem right, please ensure you're on version of Insiders (today's or later - you can use in the command palette to check), and leave a comment letting us know what isn't working as expected. Happy Coding!
/verified

Discussion:
import { isObject, isString, isUndefined, isNumber, withNullAsUndefined } from 'vs/base/common/types'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; <del> import { IEditorIdentifier, IEditorCommandsContext, CloseDirection, IVisibleEditorPane, EditorsOrder, EditorInputCapabilities, isEditorIdentifier, isEditorInputWithOptionsAndGroup, IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor'; </del> <ins> import { IEditorIdentifier, IEditorCommandsContext, CloseDirection, IVisibleEditorPane, EditorsOrder, EditorInputCapabilities, isEditorIdentifier, isEditorInputWithOptionsAndGroup, IUntitledTextResourceEditorInput, isUntitledWithAssociatedResource } from 'vs/workbench/common/editor'; </ins> import { TextCompareEditorVisibleContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, ActiveEditorStickyContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, TextCompareEditorActiveContext, SideBySideEditorActiveContext } from 'vs/workbench/common/contextkeys'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { EditorGroupColumn, columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn';

const resource = URI.isUri(resourceOrString) ? resourceOrString : URI.parse(resourceOrString); let input: IResourceEditorInput | IUntitledTextResourceEditorInput; <del> if (matchesScheme(resource, Schemas.untitled) && resource.path.length > 1) { </del> <ins> if (isUntitledWithAssociatedResource(resource)) { </ins> // special case for untitled: we are getting a resource with meaningful // path from an extension to use for the untitled editor. as such, we // have to assume it as an associated resource to use when saving. we

return candidate.resource === undefined || candidate.resource.scheme === Schemas.untitled || candidate.forceUntitled === true; } <ins> const UNTITLED_WITHOUT_ASSOCIATED_RESOURCE_REGEX = /Untitled-d+/; export function isUntitledWithAssociatedResource(resource: URI): boolean { return resource.scheme === Schemas.untitled && resource.path.length > 1 && !UNTITLED_WITHOUT_ASSOCIATED_RESOURCE_REGEX.test(resource.path); } </ins> export function isResourceMergeEditorInput(editor: unknown): editor is IResourceMergeEditorInput { if (isEditorInput(editor)) { return false; // make sure to not accidentally match on typed editor inputs

import { Schemas } from 'vs/base/common/network'; import { Disposable } from 'vs/base/common/lifecycle'; import { URI, UriComponents } from 'vs/base/common/uri'; <del> import { IEditorSerializer } from 'vs/workbench/common/editor'; </del> <ins> import { IEditorSerializer, isUntitledWithAssociatedResource } from 'vs/workbench/common/editor'; </ins> import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { ITextEditorService } from 'vs/workbench/services/textfile/common/textEditorService'; import { isEqual, toLocalResource } from 'vs/base/common/resources';

export class UntitledTextEditorWorkingCopyEditorHandler extends Disposable implements IWorkbenchContribution { <del> private static readonly UNTITLED_REGEX = /Untitled-d+/; </del> constructor( @IWorkingCopyEditorService private readonly workingCopyEditorService: IWorkingCopyEditorService, @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,

createEditor: workingCopy => { let editorInputResource: URI; <del> // This is a (weak) strategy to find out if the untitled input had // an associated file path or not by just looking at the path. and // if so, we must ensure to restore the local resource it had. if (!UntitledTextEditorWorkingCopyEditorHandler.UNTITLED_REGEX.test(workingCopy.resource.path)) { </del> <ins> // If the untitled has an associated resource, // ensure to restore the local resource it had if (isUntitledWithAssociatedResource(workingCopy.resource)) { </ins> editorInputResource = toLocalResource(workingCopy.resource, this.environmentService.remoteAuthority, this.pathService.defaultUriScheme); } else { editorInputResource = workingCopy.resource;

import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel'; import { CancellationToken } from 'vs/base/common/cancellation'; <del> import { EditorInputCapabilities } from 'vs/workbench/common/editor'; </del> <ins> import { EditorInputCapabilities, isUntitledWithAssociatedResource } from 'vs/workbench/common/editor'; </ins> import { DisposableStore } from 'vs/base/common/lifecycle'; import { isReadable, isReadableStream } from 'vs/base/common/stream'; import { readableToBuffer, streamToBuffer, VSBufferReadable, VSBufferReadableStream } from 'vs/base/common/buffer';

const input1 = instantiationService.createInstance(UntitledTextEditorInput, service.create()); await input1.resolve(); assert.strictEqual(service.get(input1.resource), input1.model); <ins> assert.ok(!isUntitledWithAssociatedResource(input1.resource)); </ins> assert.ok(service.get(input1.resource)); assert.ok(!service.get(URI.file('testing')));

}); const model = service.create({ associatedResource: file }); <ins> assert.ok(isUntitledWithAssociatedResource(model.resource)); </ins> const untitled = instantiationService.createInstance(UntitledTextEditorInput, model); assert.ok(untitled.isDirty()); assert.strictEqual(model, onDidChangeDirtyModel);