Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "gf" in es6 import statements by adding the file extension #1227

Merged
merged 1 commit into from
Jan 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/cmd_line/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs"
import * as node from "../node";

export enum FilePosition {
Expand Down Expand Up @@ -73,9 +74,26 @@ export class FileCommand extends node.CommandBase {
path.join(path.dirname(currentFilePath), this._arguments.name);

if (newFilePath !== currentFilePath) {
const newFileDoesntExist = !await this.fileExists(newFilePath);
const newFileHasNoExtname = path.extname(newFilePath) === '';
if(newFileDoesntExist && newFileHasNoExtname) {
const pathWithExtname = newFilePath + path.extname(currentFilePath)
if(await this.fileExists(pathWithExtname)) {
newFilePath = pathWithExtname;
}
}

let folder = vscode.Uri.file(newFilePath);
await vscode.commands.executeCommand("vscode.open", folder,
this._arguments.position === FilePosition.NewWindow ? this.getViewColumnToRight() : this.getActiveViewColumn());
}
}
}

protected async fileExists(filePath: string) {
return new Promise<boolean>((resolve, reject) => {
fs.stat(filePath, async (error, stat) => {
resolve(!error)
});
});
}
}