#add linter
This commit is contained in:
parent
858352b45c
commit
18063878dd
5
resources/hdlParser/index.d.ts
vendored
5
resources/hdlParser/index.d.ts
vendored
@ -1,5 +1,5 @@
|
|||||||
import { RawHdlModule, Macro, RawSymbol } from '../../src/hdlParser/common';
|
import type { RawHdlModule, Macro, RawSymbol, Error } from '../../src/hdlParser/common';
|
||||||
import { HdlLangID } from '../../src/global/enum';
|
import type { HdlLangID } from '../../src/global/enum';
|
||||||
|
|
||||||
type AbsPath = string;
|
type AbsPath = string;
|
||||||
type RelPath = string;
|
type RelPath = string;
|
||||||
@ -15,6 +15,7 @@ interface All {
|
|||||||
content: RawSymbol[]
|
content: RawSymbol[]
|
||||||
languageId: HdlLangID
|
languageId: HdlLangID
|
||||||
macro: Macro
|
macro: Macro
|
||||||
|
error: Error[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function vlogFast(path: AbsPath): Promise<Fast | undefined>;
|
export function vlogFast(path: AbsPath): Promise<Fast | undefined>;
|
||||||
|
@ -11,6 +11,7 @@ import * as lspHover from './lsp/hover';
|
|||||||
import * as lspFormatter from '../../resources/formatter';
|
import * as lspFormatter from '../../resources/formatter';
|
||||||
import * as lspTranslator from '../../resources/translator';
|
import * as lspTranslator from '../../resources/translator';
|
||||||
import * as lspDocSemantic from './lsp/docSemantic';
|
import * as lspDocSemantic from './lsp/docSemantic';
|
||||||
|
import * as lspLinter from './lsp/linter';
|
||||||
|
|
||||||
import * as tool from './tool';
|
import * as tool from './tool';
|
||||||
|
|
||||||
@ -76,11 +77,15 @@ function registerLsp(context: vscode.ExtensionContext) {
|
|||||||
vscode.languages.registerCompletionItemProvider(vlogSelector, lspCompletion.vlogPositionPortProvider, '.');
|
vscode.languages.registerCompletionItemProvider(vlogSelector, lspCompletion.vlogPositionPortProvider, '.');
|
||||||
vscode.languages.registerCompletionItemProvider(vlogSelector, lspCompletion.vlogCompletionProvider);
|
vscode.languages.registerCompletionItemProvider(vlogSelector, lspCompletion.vlogCompletionProvider);
|
||||||
vscode.languages.registerDocumentSemanticTokensProvider(vlogSelector, lspDocSemantic.vlogDocSenmanticProvider, lspDocSemantic.vlogLegend);
|
vscode.languages.registerDocumentSemanticTokensProvider(vlogSelector, lspDocSemantic.vlogDocSenmanticProvider, lspDocSemantic.vlogLegend);
|
||||||
|
lspLinter.registerVlogLinterServer();
|
||||||
|
|
||||||
|
|
||||||
// vhdl lsp
|
// vhdl lsp
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function registerToolCommands(context: vscode.ExtensionContext) {
|
function registerToolCommands(context: vscode.ExtensionContext) {
|
||||||
vscode.commands.registerCommand('digital-ide.lsp.tool.insertTextToUri', tool.insertTextToUri);
|
vscode.commands.registerCommand('digital-ide.lsp.tool.insertTextToUri', tool.insertTextToUri);
|
||||||
vscode.commands.registerCommand('digital-ide.lsp.tool.transformOldPropertyFile', tool.transformOldPpy);
|
vscode.commands.registerCommand('digital-ide.lsp.tool.transformOldPropertyFile', tool.transformOldPpy);
|
||||||
|
5
src/function/lsp/linter/index.ts
Normal file
5
src/function/lsp/linter/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { registerVlogLinterServer } from './vlog';
|
||||||
|
|
||||||
|
export {
|
||||||
|
registerVlogLinterServer
|
||||||
|
};
|
89
src/function/lsp/linter/vlog.ts
Normal file
89
src/function/lsp/linter/vlog.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import * as vscode from 'vscode';
|
||||||
|
import { All } from '../../../../resources/hdlParser';
|
||||||
|
import { hdlParam, HdlSymbol } from '../../../hdlParser';
|
||||||
|
import { Position, Range } from '../../../hdlParser/common';
|
||||||
|
|
||||||
|
|
||||||
|
class VlogLinter {
|
||||||
|
diagnostic: vscode.DiagnosticCollection;
|
||||||
|
constructor() {
|
||||||
|
this.diagnostic = vscode.languages.createDiagnosticCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
async lint(document: vscode.TextDocument) {
|
||||||
|
const filePath = document.fileName;
|
||||||
|
const vlogAll = await HdlSymbol.all(filePath);
|
||||||
|
if (vlogAll) {
|
||||||
|
const diagnostics = this.provideDiagnostics(document, vlogAll);
|
||||||
|
this.diagnostic.set(document.uri, diagnostics);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private provideDiagnostics(document: vscode.TextDocument, all: All): vscode.Diagnostic[] {
|
||||||
|
const diagnostics: vscode.Diagnostic[] = [];
|
||||||
|
if (all.error && all.error.length > 0) {
|
||||||
|
for (const hdlError of all.error) {
|
||||||
|
const range = this.makeCorrectRange(document, hdlError.range);
|
||||||
|
const diag = new vscode.Diagnostic(range, hdlError.message, hdlError.severity);
|
||||||
|
diag.source = hdlError.source;
|
||||||
|
diagnostics.push(diag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(diagnostics);
|
||||||
|
|
||||||
|
return diagnostics;
|
||||||
|
}
|
||||||
|
|
||||||
|
private makeCorrectRange(document: vscode.TextDocument, range: Position): vscode.Range {
|
||||||
|
range.line --;
|
||||||
|
if (range.character === 0 && range.line > 0) {
|
||||||
|
range.line --;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (range.line > 0) {
|
||||||
|
const lineContent = document.lineAt(range.line).text;
|
||||||
|
if (lineContent.trim().length > 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
range.line --;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentLine = document.lineAt(range.line).text;
|
||||||
|
if (range.character === 0 && currentLine.trim().length > 0) {
|
||||||
|
range.character = currentLine.trimEnd().length;
|
||||||
|
}
|
||||||
|
console.log(range);
|
||||||
|
|
||||||
|
const position = new vscode.Position(range.line, range.character);
|
||||||
|
const wordRange = document.getWordRangeAtPosition(position, /[`_0-9a-zA-Z]+/);
|
||||||
|
if (wordRange) {
|
||||||
|
return wordRange;
|
||||||
|
} else {
|
||||||
|
const errorEnd = new vscode.Position(range.line, range.character + 1);
|
||||||
|
const errorRange = new vscode.Range(position, errorEnd);
|
||||||
|
return errorRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(document: vscode.TextDocument) {
|
||||||
|
this.diagnostic.delete(document.uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerVlogLinterServer() {
|
||||||
|
const linter = new VlogLinter();
|
||||||
|
vscode.workspace.onDidOpenTextDocument(doc => {
|
||||||
|
linter.lint(doc);
|
||||||
|
});
|
||||||
|
vscode.workspace.onDidSaveTextDocument(doc => {
|
||||||
|
linter.lint(doc);
|
||||||
|
});
|
||||||
|
vscode.workspace.onDidCloseTextDocument(doc => {
|
||||||
|
linter.remove(doc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
registerVlogLinterServer
|
||||||
|
};
|
@ -78,10 +78,12 @@ enum InstModPathStatus {Current, Include, Others, Unknown};
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
interface Error {
|
interface Error {
|
||||||
severity: number
|
severity: vscode.DiagnosticSeverity
|
||||||
message: string
|
message: string
|
||||||
source: string
|
source: string
|
||||||
range: Range
|
range: Position
|
||||||
|
running_mode?: string
|
||||||
|
running_phase?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
interface DefineParam {
|
interface DefineParam {
|
||||||
|
@ -8,9 +8,5 @@ module mux2to1(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
assign outp = sel == 1'b0 ? a : b;
|
assign outp = sel == 1'b0 ? a : b;
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
Loading…
x
Reference in New Issue
Block a user