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

Resolve goToLingoToml for Windows #183

Merged
merged 3 commits into from
Oct 20, 2024
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
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { registerCollapseAllCommand,
registerGoToFileCommand,
registerGoToLingoTomlCommand,
registerImportReactorCommand,
registerIncludeProjectCommand,
registerOpenFolderCommand,
registerOpenInSplitViewCommand,
registerOpenInTerminalCommand,
Expand Down Expand Up @@ -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);

Expand Down
26 changes: 10 additions & 16 deletions src/lfview/lf-data-provider-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
));
Expand All @@ -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) => {
Expand Down
42 changes: 18 additions & 24 deletions src/lfview/lf-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,18 +674,15 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod
* @param node - The node representing the reactor to import.
* @returns A Promise that resolves when the import text has been added to the active editor and the document saved.
*/
async importReactorCommand(node: LFDataProviderNode) {
const editor = vscode.window.activeTextEditor;
if (editor) {
if (!editor.document.uri.fsPath.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);
async importReactorCommand(node: LFDataProviderNode, editor: vscode.TextEditor): Promise<void> {
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);
}

/**
Expand All @@ -695,18 +692,15 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod
* @param node - The node representing the reactor to import.
* @returns A Promise that resolves when the import text has been added to the active editor and the document saved.
*/
async importLibraryReactorCommand(node: LFDataProviderNode) {
const editor = vscode.window.activeTextEditor;
if (editor) {
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);
async importLibraryReactorCommand(node: LFDataProviderNode, editor: vscode.TextEditor): Promise<void> {
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);
}

/**
Expand Down Expand Up @@ -796,15 +790,15 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod
* @param node - The LFDataProviderNode for which to open the Lingo.toml file.
*/
goToLingoTomlCommand(node: LFDataProviderNode) {
const segments = node.uri.fsPath.split('/');
const segments = node.uri.path.split('/');
const srcIdx = segments.lastIndexOf('build');

if (srcIdx === -1) {
vscode.window.showErrorMessage('Invalid URI: "build" directory not found.');
return;
}

let newUri = segments.slice(0, srcIdx).join('/').concat('/Lingo.toml');
let newUri = segments.slice(0, srcIdx).join(path.sep).concat(`${path.sep}Lingo.toml`);

vscode.workspace.openTextDocument(vscode.Uri.file(newUri))
.then(doc => {
Expand Down
Loading