diff --git a/package.json b/package.json index 0d1270235..56a76f957 100644 --- a/package.json +++ b/package.json @@ -223,11 +223,6 @@ "group": "inline@1", "when": "viewItem == project" }, - { - "command": "linguafranca.includeProject", - "group": "inline@1", - "when": "viewItem == root || viewItem == file-local" - }, { "command": "linguafranca.goToFile", "group": "inline@2", diff --git a/src/extension.ts b/src/extension.ts index 15c1e4d23..3387285c5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -16,7 +16,6 @@ import { registerCollapseAllCommand, registerGoToFileCommand, registerGoToLingoTomlCommand, registerImportReactorCommand, - registerIncludeProjectCommand, registerOpenFolderCommand, registerOpenInSplitViewCommand, registerOpenInTerminalCommand, @@ -98,7 +97,6 @@ export async function activate(context: vscode.ExtensionContext) { registerImportReactorCommand(context, lfDataProvider); registerCollapseAllCommand(context); registerGoToLingoTomlCommand(context, lfDataProvider); - registerIncludeProjectCommand(context, lfDataProvider); registerOpenInTerminalCommand(context); registerOpenFolderCommand(context); diff --git a/src/lfview/lf-data-provider-commands.ts b/src/lfview/lf-data-provider-commands.ts index 9f4805d4e..49bf519d7 100644 --- a/src/lfview/lf-data-provider-commands.ts +++ b/src/lfview/lf-data-provider-commands.ts @@ -49,11 +49,17 @@ export function registerOpenInSplitViewCommand(context: vscode.ExtensionContext, export function registerImportReactorCommand(context: vscode.ExtensionContext, provider: LFDataProvider) { context.subscriptions.push(vscode.commands.registerCommand( 'linguafranca.importReactor', async (node: LFDataProviderNode) => { - if(node.type === LFDataProviderNodeType.LOCAL) { - await provider.importReactorCommand(node); + const editor = vscode.window.activeTextEditor; + + if (!editor) { + vscode.window.showErrorMessage('No active editor found.'); + return; } - else { - await provider.importLibraryReactorCommand(node); + + if (node.type === LFDataProviderNodeType.LOCAL) { + await provider.importReactorCommand(node, editor); + } else { + await provider.importLibraryReactorCommand(node, editor); } } )); @@ -79,18 +85,6 @@ export function registerGoToLingoTomlCommand(context: vscode.ExtensionContext, p )); } -export function registerIncludeProjectCommand(context: vscode.ExtensionContext, provider: LFDataProvider) { - context.subscriptions.push(vscode.commands.registerCommand( - 'linguafranca.includeProject', (node: LFDataProviderNode) => { - vscode.window.showInformationMessage('The "Include Project" feature is not implemented yet.', 'Details').then(selection => { - if (selection === "Details") { - vscode.window.showInformationMessage('Please use the Lingo command line to include the selected library in your current project. Once included, the library will appear under the "Lingo Packages" section.'); - } - }); - } - )); -} - export function registerOpenInTerminalCommand(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.commands.registerCommand( 'linguafranca.openInTerminal', (node: LFDataProviderNode) => { diff --git a/src/lfview/lf-data-provider.ts b/src/lfview/lf-data-provider.ts index 75cedabc9..45244bff4 100644 --- a/src/lfview/lf-data-provider.ts +++ b/src/lfview/lf-data-provider.ts @@ -674,18 +674,15 @@ export class LFDataProvider implements vscode.TreeDataProvider { + if (!editor.document.uri.path.endsWith('.lf')) { + vscode.window.showErrorMessage('The active editor must be a Ligua Franca program.'); + return; } + const relativePath = this.getRelativePath(editor.document.uri.path, node.uri.path); + const importText = `import ${node.label!.toString()} from "${relativePath}"\n`; + const position = await this.getTargetPosition(editor.document.uri); + this.addTextOnActiveEditor(editor, position!.end, importText); } /** @@ -695,18 +692,15 @@ export class LFDataProvider implements vscode.TreeDataProvider\n`; - const position = await this.getTargetPosition(editor.document.uri); - this.addTextOnActiveEditor(editor, position!.end, importText); + async importLibraryReactorCommand(node: LFDataProviderNode, editor: vscode.TextEditor): Promise { + if (!editor.document.uri.fsPath.endsWith('.lf')) { + vscode.window.showErrorMessage('The active editor must be a Ligua Franca program.'); + return; } + const relativePath = this.getLibraryPath(node.uri.path); + const importText = `import ${node.label!.toString()} from <${relativePath}>\n`; + const position = await this.getTargetPosition(editor.document.uri); + this.addTextOnActiveEditor(editor, position!.end, importText); } /** @@ -796,7 +790,7 @@ export class LFDataProvider implements vscode.TreeDataProvider {