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

Fix linters and some errors #146

Merged
merged 2 commits into from
Apr 28, 2021
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
"scope": "window",
"type": "string",
"default": "",
"description": "Add Modelsim arguments here. They will be added to xvlog while linting."
"description": "Add xvlog arguments here. They will be added to xvlog while linting."
},
"verilog.linting.iverilog.arguments": {
"scope": "window",
Expand Down
4 changes: 2 additions & 2 deletions src/ctags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export class CtagsManager {
commands.executeCommand('vscode.executeDocumentSymbolProvider', doc.uri);
}

onDidChangeActiveTextEditor(editor: TextEditor) {
if (!this.isOutputPanel(editor.document.uri)) {
onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
if (editor && !this.isOutputPanel(editor.document.uri)) {
console.log("on open");
CtagsManager.ctags.setDocument(editor.document);
CtagsManager.ctags.index();
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function activate(context: ExtensionContext) {
// Configure command to instantiate a module
commands.registerCommand("verilog.instantiateModule", ModuleInstantiation.instantiateModuleInteract);
// Register command for manual linting
commands.registerCommand("verilog.lint", lintManager.RunLintTool);
commands.registerCommand("verilog.lint", lintManager.RunLintTool, lintManager);

// Configure svls language server
configLanguageServer();
Expand Down
5 changes: 5 additions & 0 deletions src/linter/LintManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default class LintManager {

workspace.onDidChangeConfiguration(this.configLinter, this, this.subscriptions);
this.configLinter();

// Run linting for open documents on launch
window.visibleTextEditors.forEach(editor => {
this.lint(editor.document);
});
}

configLinter() {
Expand Down
2 changes: 1 addition & 1 deletion src/linter/VerilatorLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class VerilatorLinter extends BaseLinter {
// Parse output lines
lines.forEach((line, i) => {
// Error for our file
if (line.startsWith('%') && line.search(docUri) > 0) {
if (line.startsWith('%') && line.indexOf(docUri) > 0) {
let rex = line.match(/%(\w+)(-[A-Z0-9_]+)?:\s*(\w+:)?(?:[^:]+):\s*(\d+):(?:\s*(\d+):)?\s*(\s*.+)/);

if (rex && rex[0].length > 0) {
Expand Down
19 changes: 10 additions & 9 deletions src/linter/XvlogLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class XvlogLinter extends BaseLinter {
protected lint(doc: TextDocument) {
this.logger.log('xvlog lint requested');
let svArgs: string = (doc.languageId == "systemverilog") ? "-sv" : ""; //Systemverilog args
let command = "xvlog " + svArgs + " -nolog " + this.xvlogArgs + "\"" + doc.fileName + "\"";
let command = "xvlog " + svArgs + " -nolog " + this.xvlogArgs + " \"" + doc.fileName + "\"";
this.logger.log(command, Log_Severity.Command);

let process: ChildProcess = exec(command, (error: Error, stdout: string, stderr: string) => {
Expand All @@ -31,24 +31,25 @@ export default class XvlogLinter extends BaseLinter {
let lines = stdout.split(/\r?\n/g);
lines.forEach((line) => {

let tokens = line.split(/:?\s*(?:\[|\])\s*/).filter(Boolean);
if (tokens.length < 4
|| tokens[0] != "ERROR"
|| !tokens[1].startsWith("VRFC")) {
let match = line.match(/^(ERROR|WARNING):\s+\[(VRFC\b[^\]]*)\]\s+(.*\S)\s+\[(.*):(\d+)\]\s*$/);
if (!match) {
return;
}

let severity = (match[1] === "ERROR") ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning;

// Get filename and line number
let [filename, lineno_str] = tokens[3].split(/:(\d+)/);
let filename = match[4];
let lineno_str = match[5];
let lineno = parseInt(lineno_str) - 1;

// if (filename != doc.fileName) // Check that filename matches
// return;

let diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Error,
code: tokens[1],
message: "[" + tokens[1] + "] " + tokens[2],
severity: severity,
code: match[2],
message: "[" + match[2] + "] " + match[3],
range: new Range(lineno, 0, lineno, Number.MAX_VALUE),
source: "xvlog",
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/DefinitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class VerilogDefinitionProvider implements DefinitionProvider {
return new Promise((resolve, reject) => {
// get word start and end
let textRange = document.getWordRangeAtPosition(position);
if (textRange.isEmpty)
if (!textRange || textRange.isEmpty)
return;
// hover word
let targetText = document.getText(textRange);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/HoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class VerilogHoverProvider implements HoverProvider {
this.logger.log("Hover requested");
// get word start and end
let textRange = document.getWordRangeAtPosition(position);
if (textRange.isEmpty)
if (!textRange || textRange.isEmpty)
return;
// hover word
let targetText = document.getText(textRange);
Expand Down