Change:
Issue Type: <bBug</bCreating an untitled document (from a file URI amended with the scheme) results in different states depending on whether the document is created with the command or the function. I tried to reduce the problem to a failing test case and failed, but maybe can still be useful for debugging. Create an untitled URI for a new file () Open an editor for that URI with / Type some text Save the file Notice that the save dialog starts with the we had providedCreate a new untitled URI for a new file Open an editor for that URI with Type some text Save the file The save dialog starts with the we had provided, just like with the other method. The save dialog starts with the text we typed instead of the we had provided. VS Code version: Code 1.63.0 (, 2021-12-07T05:16:45.441Z) OS version: Linux x64 5.15.6-200.fc35.x8664 Restricted Mode: No <details<summarySystem Info</summary </details<details<summaryExtensions (38)</summaryExtensionVersion ------ vscode-unfancy-file-icons3.15.0 icons-carbon0.2.4 chalice-icon-theme1.2.16 awk-ide-vscode0.6.2 vscode-fish1.0.24 init-script0.1.3 make-task-provider2.1.1 npm-intellisense1.4.0 path-intellisense2.6.0 vscode-eslint2.2.2 EditorConfig0.16.4 gtk-dark-titlebar1.2.3 vscode-pull-request-github0.34.0 go0.29.0 terraform2.17.0 nix-ide0.1.18 language-julia1.5.6 rust-analyzer0.2.842 git-graph1.30.0 fluent-icons0.0.15 direnv0.3.0 vscode-docker1.18.0 python2021.12. vscode-pylance2021.12.1 jupyter2021.11. jupyter-keymap1.0.0 jupyter-renderers1.0.4 remote-containers0.209.5 remote-ssh0.68.0 remote-ssh-edit0.68.0 vsliveshare1.0.5196 vscode-commons0.0.6 vscode-yaml1.2.2 edit-with-shell1.3.0 lua2.5.3 even-better-toml0.14.2 shellcheck0.18.2 redo0.1.0 (6 theme extensions excluded) </details<!-- generated by issue reporter --
Looks like when you call we treat the URI as the associated resource: But we do not do the same from
I tried this with the following code: and both files saved to the correct paths... but I wasn't prompted at all by a file dialog. Is that expected?
Yes. Untitled with associated path don't ask for a file name, that is the whole idea of "untitled with associated resource" vs. "untitled without associated resource".

Discussion:
return Promise.all([a, b, c, d]); }); <ins> test('api-command: vscode.open with untitled supports associated resource (#138925)', async function () { let uri = Uri.parse(workspace.workspaceFolders![0].uri.toString() + '/far-copy.js').with({ scheme: 'untitled' }); await commands.executeCommand('vscode.open', uri).then(() => assert.ok(true), () => assert.ok(false)); // untitled with associated resource are dirty from the beginning assert.ok(window.activeTextEditor?.document.isDirty); }); </ins> });

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 { TextCompareEditorVisibleContext, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IVisibleEditorPane, ActiveEditorStickyContext, EditorsOrder, EditorInputCapabilities, isEditorIdentifier, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, GroupIdentifier, TextCompareEditorActiveContext, SideBySideEditorActiveContext, isEditorInputWithOptionsAndGroup } from 'vs/workbench/common/editor'; </del> <ins> import { TextCompareEditorVisibleContext, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IVisibleEditorPane, ActiveEditorStickyContext, EditorsOrder, EditorInputCapabilities, isEditorIdentifier, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, GroupIdentifier, TextCompareEditorActiveContext, SideBySideEditorActiveContext, isEditorInputWithOptionsAndGroup, IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor'; </ins> import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { EditorGroupColumn, columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { ACTIVE_GROUP_TYPE, IEditorService, SIDE_GROUP, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService';

import { CATEGORIES } from 'vs/workbench/common/actions'; import { ActiveGroupEditorsByMostRecentlyUsedQuickAccess } from 'vs/workbench/browser/parts/editor/editorQuickAccess'; import { IOpenerService } from 'vs/platform/opener/common/opener'; <del> import { EditorResolution, IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor'; </del> <ins> import { EditorResolution, IEditorOptions, IResourceEditorInput, ITextEditorOptions } from 'vs/platform/editor/common/editor'; </ins> import { Schemas } from 'vs/base/common/network'; import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput'; import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; import { IEditorResolverService } from 'vs/workbench/services/editor/common/editorResolverService'; <ins> import { IPathService } from 'vs/workbench/services/path/common/pathService'; </ins> export const CLOSE_SAVED_EDITORS_COMMAND_ID = 'workbench.action.closeUnmodifiedEditors'; export const CLOSE_EDITORS_IN_GROUP_COMMAND_ID = 'workbench.action.closeEditorsInGroup';

const editorService = accessor.get(IEditorService); const editorGroupService = accessor.get(IEditorGroupsService); const openerService = accessor.get(IOpenerService); <ins> const pathService = accessor.get(IPathService); </ins> const resource = URI.revive(resourceArg); const [columnArg, optionsArg] = columnAndOptions ?? []; <del> // use editor options or editor view column as a hint to use the editor service for opening if (optionsArg || typeof columnArg === 'number') { </del> <ins> // use editor options or editor view column or resource scheme // as a hint to use the editor service for opening directly if (optionsArg || typeof columnArg === 'number' || resource.scheme === Schemas.untitled) { </ins> const [options, column] = mixinContext(context, optionsArg, columnArg); <del> await editorService.openEditor({ resource, options, label }, columnToEditorGroup(editorGroupService, column)); </del> <ins> let input: IResourceEditorInput | IUntitledTextResourceEditorInput; if (resource.scheme === Schemas.untitled && resource.path.length > 1) { // 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 // do so by setting the `forceUntitled: true` and changing the scheme // to a file based one. the untitled editor service takes care to // associate the path properly then. input = { resource: resource.with({ scheme: pathService.defaultUriScheme }), forceUntitled: true, options, label }; } else { // use any other resource as is input = { resource, options, label }; } await editorService.openEditor(input, columnToEditorGroup(editorGroupService, column)); </ins> } // do not allow to execute commands from here