Skip to content

Commit

Permalink
Added a way so that rules and ls can be retrieved from an SVN reposit…
Browse files Browse the repository at this point in the history
…ory.
  • Loading branch information
sconwayaus committed Jun 25, 2024
1 parent 21abe83 commit 52550a5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The language server provides a couple of features from the [Verible SystemVerilo
* **Linting**: Checks your code against a number of
[lint rules](https://chipsalliance.github.io/verible/lint.html) and provides
'wiggly lines' with diagnostic output and even offers auto-fixes when available.
* ***Configuration***: Linting configuration is now sourced from an SVN repo so
that teams can work from the same set of rules. @see Prerequisites below.
* **Formatting**: Offers Format Document/Selection according to the Verible
formatting style. The 'look' can be configured if needed.
* **Outline**: Shows the high-level structure of your modules and functions in the
Expand All @@ -35,5 +37,6 @@ The language server provides a couple of features from the [Verible SystemVerilo
* **[🎉 New]** `AUTOREG` – declares regs for outputs not connected to
any module instance.

## Prerequisite on your machine
None, all Windows executables are bundled into the extension.
## Prerequisites
1. An SVN repo with a copy of the verible-verilog-ls.exe and .rules.verible_lint file. A copy of verible and associated rules file are included with this extension, but users will need to add these to their SVN repo.
2. In the exteions settings, set the svn_path in stevesSystemVerilogExtension.rules_config.svn_path to point to the SVN repo.
23 changes: 7 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Steve's System Verilog Extension",
"author": "Steve Conway",
"license": "MIT",
"version": "0.2.0",
"version": "0.2.1",
"repository": {
"type": "git",
"url": "https://github.com/sconwayaus/StevesSystemVerilogExtension"
Expand Down Expand Up @@ -300,20 +300,11 @@
"type": "object",
"title": "Steve's System Verilog Extension",
"properties": {
"stevesSystemVerilogExtension.languageServer.path": {
"stevesSystemVerilogExtension.rules_config.svn_path": {
"type": "string",
"default": "./bin/verible-verilog-ls",
"default": "",
"scope": "machine-overridable",
"description": "The path to verible-verilog-ls executable, e.g.: /usr/bin/verible-verilog-ls.",
"order": 0
},
"stevesSystemVerilogExtension.languageServer.rules_config": {
"type": "string",
"default": "./bin/.rules.verible_lint",
"items": {
"type": "string"
},
"description": "Verible rules config file path (default: './bin/.rules.verible_lint')",
"description": "SVN path to a directory containing verible.filelist.\nExample: https://server/repos/trunk/verible_rules",
"order": 1
},
"stevesSystemVerilogExtension.languageServer.arguments": {
Expand All @@ -323,21 +314,21 @@
"type": "string"
},
"description": "Arguments for verible-verilog-ls server.",
"order": 1
"order": 2
},
"stevesSystemVerilogExtension.projectFileList.includeGlobPattern": {
"type": "string",
"default": "{**/*.sv,**/.*v,**/*.svh}",
"scope": "machine-overridable",
"description": "Include file glob pattern for creating a project file list (verible.filelist).",
"order": 2
"order": 3
},
"stevesSystemVerilogExtension.projectFileList.excludeGlobPattern": {
"type": "string",
"default": "{**/db/,**/incremental_db/,**/output/}",
"scope": "machine-overridable",
"description": "Exclude file glob pattern for creating a project file list (verible.filelist).",
"order": 3
"order": 4
}
}
},
Expand Down
35 changes: 23 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { initProjectFileList } from './projectFileList';
import { svnCheckout } from './svn';

import * as vscode from 'vscode';
import * as vscodelc from 'vscode-languageclient/node';
import { initProjectFileList } from './projectFileList';

// Global object to dispose of previous language clients.
let client: undefined | vscodelc.LanguageClient = undefined;

async function initLanguageClient(context: vscode.ExtensionContext, output: vscode.OutputChannel) {
const config = vscode.workspace.getConfiguration('stevesSystemVerilogExtension.languageServer');

const binary_path = context.asAbsolutePath(config.get('path') as string);

const rules_config_arg_value = context.asAbsolutePath(config.get('rules_config') as string);
// Source the ls and rules from SVN
var binary_path = context.asAbsolutePath("./bin/svn/verible-verilog-ls");
const rules_config_arg_value = context.asAbsolutePath("./bin/svn/.rules.verible_lint");

const rules_config_arg = ["--rules_config", rules_config_arg_value];
const user_args = config.get('arguments') as string;
Expand Down Expand Up @@ -44,8 +46,18 @@ async function initLanguageClient(context: vscode.ExtensionContext, output: vsco
client.start();
}

async function start_extension(context: vscode.ExtensionContext, output: vscode.OutputChannel) {
// Checkout SVN
await svnCheckout(context, output);

// Init code to manage the project file list
await initProjectFileList(context, output);

return initLanguageClient(context, output);
}

// VSCode entrypoint to bootstrap an extension
export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {
const output = vscode.window.createOutputChannel('Verible Language Server');

// If a configuration change even it fired, let's dispose
Expand All @@ -55,17 +67,16 @@ export function activate(context: vscode.ExtensionContext) {
return;
}
if (!client) {
return initLanguageClient(context, output);
output.append("Config Changed: No Client");
return start_extension(context, output);
}
client.stop().finally(() => {
initLanguageClient(context, output);
client.stop().finally(async () => {
output.append("Config Changed...");
start_extension(context, output);
});
});

// Init code to manage the project file list
initProjectFileList(context, output);

return initLanguageClient(context, output);
return start_extension(context, output);
}

// Entrypoint to tear it down.
Expand Down
50 changes: 50 additions & 0 deletions src/svn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as vscode from 'vscode';
import * as cp from "child_process";
import * as fs from 'fs';

const execShell = (cmd: string, output: vscode.OutputChannel) =>
new Promise<string>((resolve, reject) => {
output.appendLine("Executing: '" + cmd + "'");
cp.exec(cmd, (err, out) => {
if (err) {
return reject(err);
}
return resolve(out);
});
});


export async function svnCheckout(context: vscode.ExtensionContext, output: vscode.OutputChannel) {
output.appendLine("Checking out SVN repo");

// Check if the SVN location is valid in settings
const config = vscode.workspace.getConfiguration('stevesSystemVerilogExtension.rules_config');
const svn_path = config.get('svn_path') as string;

const path = "\"" + context.asAbsolutePath("./bin/svn") + "\"";
const path_exists = fs.existsSync(path);

var cmd_revert = "svn revert -R " + path;
try {
const revert_text = await execShell(cmd_revert, output);
output.appendLine("svn revert: " + revert_text);
} catch (er) {
console.log(er); // 'rejected'
}

var cmd_checkout = "svn checkout --force " + svn_path + " " + path;
try {
const text = await execShell(cmd_checkout, output);
output.appendLine("svn checkout: " + text);
if(!path_exists) {
vscode.window.showInformationMessage("Successfully configured SVN repo path.");
}
} catch (er) {
console.log(er); // 'rejected'
output.appendLine("SVN command failed");
vscode.window.showErrorMessage("Failed to checkout verible from SVN. Check your 'stevesSystemVerilogExtension.rules_config.svn_path' setting.");
vscode.commands.executeCommand( 'workbench.action.openSettings', 'stevesSystemVerilogExtension.rules_config.svn_path' );
}

output.appendLine("SVN Operations Complete");
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noUnusedParameters": true
},
"exclude": [
"node_modules"
"node_modules",
"bin/svn/*"
]
}

0 comments on commit 52550a5

Please sign in to comment.