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

run_gop_command #23

Merged
merged 2 commits into from
Nov 11, 2023
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: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,11 @@
"type": "boolean",
"markdownDescription": "Runs `go mod vendor` for a module.",
"default": true
},
"run_gop_command": {
"type": "boolean",
"markdownDescription": "Runs `gop command` for a project.",
"default": true
}
}
},
Expand Down
27 changes: 27 additions & 0 deletions src/gopCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

import vscode = require('vscode');

export function runGopCommand(dir: string, command: string, args: string[]): boolean {

Check warning on line 5 in src/gopCommand.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest stable

'args' is defined but never used
if (command === 'run') {
runGopTerminal(dir, 'gop run .');
return true;
}
return false;
}

function createGopTerminal(dir: string): vscode.Terminal {
for (const i in vscode.window.terminals) {
if (vscode.window.terminals[i].name === '#gop') {
const term = vscode.window.terminals[i];
term.dispose();
}
}
return vscode.window.createTerminal({ name: '#gop', cwd: dir });
}

function runGopTerminal(dir: string, text: string) {
const term = createGopTerminal(dir);
term.show(false);
term.sendText(text);
}
7 changes: 7 additions & 0 deletions src/language/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { URI } from 'vscode-uri';
import { VulncheckReport, writeVulns } from '../goVulncheck';
import { createHash } from 'crypto';
import { GoExtensionContext } from '../context';
import { runGopCommand } from '../gopCommand';

export interface LanguageServerConfig {
serverName: string;
Expand Down Expand Up @@ -555,6 +556,12 @@ export async function buildLanguageClient(
if (command === 'gopls.tidy') {
await vscode.workspace.saveAll(false);
}
if (command === 'gopls.run_gop_command') {
await vscode.workspace.saveAll(false);
if (runGopCommand(vscode.Uri.parse(args[0].URI).fsPath, args[0].Command, args[0].Args)) {
return;
}
}
const res = await next(command, args);
if (command === 'gopls.run_govulncheck') {
const progressToken = res.Token;
Expand Down
Loading