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

Added context menu command to create new worksheet #183

Merged
merged 7 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
"command": "metals.doctor-run",
"category": "Metals",
"title": "Run doctor"
},
{
"command": "metals.new-scala-file",
"category": "Metals",
"title": "New Scala File..."
}
],
"menus": {
Expand Down Expand Up @@ -229,6 +234,13 @@
"command": "metals.doctor-run",
"when": "metals:enabled"
}
],
"explorer/context": [
{
"command": "metals.new-scala-file",
"when": "metals:enabled && explorerResourceIsFolder",
"group": "navigation@4"
}
]
},
"breakpoints": [
Expand Down
4 changes: 4 additions & 0 deletions src/MetalsFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ExecuteClientCommandProvider {}
export interface DoctorProvider {}
export interface StatusBarProvider {}
export interface OpenFilesOnRenameProvider {}
export interface QuickPickProvider {}

export class MetalsFeatures implements StaticFeature {
treeViewProvider?: TreeViewProvider;
Expand All @@ -26,6 +27,7 @@ export class MetalsFeatures implements StaticFeature {
doctorProvider?: DoctorProvider;
statusBarProvider?: StatusBarProvider;
openFilesOnRenameProvider?: OpenFilesOnRenameProvider;
quickPickProvider?: QuickPickProvider;

fillInitializeParams(params: InitializeParams): void {
if (!params.capabilities.experimental) {
Expand All @@ -42,6 +44,7 @@ export class MetalsFeatures implements StaticFeature {
(params.capabilities.experimental as any).openFilesOnRenameProvider = true;
(params.capabilities.experimental as any).doctorProvider = "html";
(params.capabilities.experimental as any).statusBarProvider = "on";
(params.capabilities.experimental as any).quickPickProvider = true;
}
fillClientCapabilities(): void {}
initialize(capabilities: ServerCapabilities): void {
Expand All @@ -58,6 +61,7 @@ export class MetalsFeatures implements StaticFeature {
capabilities.experimental.openFilesOnRenameProvider;
this.doctorProvider = capabilities.experimental.doctorProvider;
this.statusBarProvider = capabilities.experimental.statusBarProvider;
this.quickPickProvider = capabilities.experimental.quickPickProvider;
}
}
}
22 changes: 21 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import {
MetalsDidFocus,
ExecuteClientCommand,
MetalsInputBox,
MetalsWindowStateDidChange
MetalsWindowStateDidChange,
MetalsQuickPick
} from "./protocol";
import { LazyProgress } from "./lazy-progress";
import * as fs from "fs";
Expand Down Expand Up @@ -508,6 +509,13 @@ function launchMetals(
});
});

registerCommand("metals.new-scala-file", async (directory: Uri) => {
return client.sendRequest(ExecuteCommandRequest.type, {
command: "new-scala-file",
arguments: [directory?.toString()]
});
});

window.onDidChangeActiveTextEditor(editor => {
if (editor && isSupportedLanguage(editor.document.languageId)) {
client.sendNotification(
Expand All @@ -533,6 +541,18 @@ function launchMetals(
});
});

client.onRequest(MetalsQuickPick.type, (params, requestToken) => {
return window
.showQuickPick(params.items, params, requestToken)
.then(result => {
if (result === undefined) {
return { cancelled: true };
} else {
return { itemId: result.id };
}
});
});

// Long running tasks such as "import project" trigger start a progress
// bar with a "cancel" button.
client.onRequest(MetalsSlowTask.type, (params, requestToken) => {
Expand Down
30 changes: 30 additions & 0 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ export interface MetalsInputBoxResult {
cancelled?: boolean;
}

export namespace MetalsQuickPick {
export const type = new RequestType<
MetalsQuickPickParams,
MetalsQuickPickResult,
void,
void
>("metals/quickPick");
}

export interface MetalsQuickPickParams {
items: MetalsQuickPickItem[];
matchOnDescription?: boolean;
matchOnDetail?: boolean;
placeHolder?: string;
ignoreFocusOut?: boolean;
}

export interface MetalsQuickPickResult {
itemId?: string;
cancelled?: boolean;
}

export interface MetalsQuickPickItem {
id: string;
label: string;
description?: string;
detail?: string;
alwaysShow?: boolean;
}

export namespace MetalsWindowStateDidChange {
export const type = new NotificationType<
MetalsWindowStateDidChangeParams,
Expand Down