Skip to content

Commit a413622

Browse files
committed
Address comments
1 parent f938d5f commit a413622

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

Diff for: src/commands/newFile.ts

+7-25
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import * as fs from "fs/promises";
1616
import * as path from "path";
1717
import * as vscode from "vscode";
18-
import { fileExists, pathExists } from "../utilities/filesystem";
1918

2019
const extension = "swift";
2120
const defaultFileName = `Untitled.${extension}`;
@@ -29,17 +28,16 @@ export async function newSwiftFile(
2928
if (uri) {
3029
// Attempt to create the file at the given directory.
3130
const dir = (await isDirectory(uri)) ? uri.fsPath : path.dirname(uri.fsPath);
32-
const defaultName = path.join(dir, defaultFileName);
33-
const givenPath = await vscode.window.showInputBox({
34-
value: defaultName,
35-
valueSelection: [dir.length + 1, defaultName.length - extension.length - 1],
36-
prompt: "Enter a file path to be created",
37-
validateInput: validatePathValid,
31+
const defaultName = vscode.Uri.file(path.join(dir, defaultFileName));
32+
const targetUri = await vscode.window.showSaveDialog({
33+
defaultUri: defaultName,
34+
title: "Enter a file path to be created",
3835
});
39-
if (!givenPath) {
36+
37+
if (!targetUri) {
4038
return;
4139
}
42-
const targetUri = vscode.Uri.file(givenPath);
40+
4341
try {
4442
await fs.writeFile(targetUri.fsPath, "", "utf-8");
4543
const document = await vscode.workspace.openTextDocument(targetUri);
@@ -56,19 +54,3 @@ export async function newSwiftFile(
5654
await vscode.window.showTextDocument(document);
5755
}
5856
}
59-
60-
async function validatePathValid(input: string) {
61-
const inputPath = vscode.Uri.file(input).fsPath;
62-
const filePathExists = await fileExists(inputPath);
63-
if (filePathExists) {
64-
return `Supplied path ${inputPath} already exists`;
65-
}
66-
67-
const inputDir = path.dirname(inputPath);
68-
const dirExists = await pathExists(inputDir);
69-
if (!dirExists) {
70-
return `Supplied directory ${inputDir} doesn't exist`;
71-
}
72-
73-
return undefined;
74-
}

Diff for: test/suite/commands/NewFile.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the VS Code Swift open source project
44
//
5-
// Copyright (c) 2023 the VS Code Swift project authors
5+
// Copyright (c) 2024 the VS Code Swift project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information

0 commit comments

Comments
 (0)