Skip to content

Commit

Permalink
Addded package object to create new
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Alefirov committed Feb 4, 2020
1 parent 832ad02 commit 64d82b7
Showing 1 changed file with 50 additions and 27 deletions.
77 changes: 50 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function fetchAndLaunchMetals(context: ExtensionContext, javaHome: string) {
if (dottyIde.enabled) {
outputChannel.appendLine(
`Metals will not start since Dotty is enabled for this workspace. ` +
`To enable Metals, remove the file ${dottyIde} and run 'Reload window'`
`To enable Metals, remove the file ${dottyIde} and run 'Reload window'`
);
return;
}
Expand Down Expand Up @@ -513,34 +513,57 @@ function launchMetals(
return undefined;
})();

const worksheetPick = { label: 'Worksheet', kind: 'worksheet' }
const classPick = { label: 'Class', kind: 'class' }
const objectPick = { label: 'Object', kind: 'object' }
const traitPick = { label: 'Trait', kind: 'trait' }

return window.showQuickPick(
[classPick, objectPick, traitPick, worksheetPick],
{ placeHolder: 'Select the kind of file to create' }
).then(kindPick => {
if (kindPick !== undefined) return window.showInputBox({ prompt: 'Enter name for the new ' + kindPick.kind }).then(name => {
if (name !== undefined) {
const arg: MetalsNewScalaFileParams =
{
'directory': directory,
'name': name,
'kind': kindPick.kind
const classPick = { label: "Class", kind: "class" };
const objectPick = { label: "Object", kind: "object" };
const traitPick = { label: "Trait", kind: "trait" };
const packageObjectPick = {
label: "Package Object",
kind: "package-object"
};
const worksheetPick = { label: "Worksheet", kind: "worksheet" };

return window
.showQuickPick(
[classPick, objectPick, traitPick, packageObjectPick, worksheetPick],
{ placeHolder: "Select the kind of file to create" }
)
.then(kindPick => {
const name = (async () => {
switch (kindPick) {
case classPick:
case objectPick:
case traitPick:
case worksheetPick:
return window.showInputBox({
prompt: "Enter name for the new " + kindPick.kind
});
case packageObjectPick:
return "";
}
client.sendRequest(ExecuteCommandRequest.type, {
command: "new-scala-file",
arguments: [arg]
}).then(result => {
workspace
.openTextDocument(Uri.parse(result))
.then(textDocument => window.showTextDocument(textDocument));
});
}
})();

name.then(name => {
if (kindPick !== undefined && name !== undefined) {
const arg: MetalsNewScalaFileParams = {
directory: directory,
name: name,
kind: kindPick.kind
};
client
.sendRequest(ExecuteCommandRequest.type, {
command: "new-scala-file",
arguments: [arg]
})
.then(result => {
workspace
.openTextDocument(Uri.parse(result))
.then(textDocument =>
window.showTextDocument(textDocument)
);
});
}
});
});
});
});

window.onDidChangeActiveTextEditor(editor => {
Expand Down

0 comments on commit 64d82b7

Please sign in to comment.