From f10f6cee1806a817f2502fa9907cc27abf4fff90 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Fri, 7 Jul 2023 02:29:43 +0800 Subject: [PATCH] #fix hover | #fix completion --- resources/hdlParser/index.js | 2 +- src/extension.ts | 44 +++++++++++++++- src/function/lsp/completion/vlog.ts | 20 ++++--- src/function/lsp/hover/vlog.ts | 2 + src/function/lsp/util/index.ts | 6 ++- src/hdlParser/common.ts | 2 + src/test/.vscode/property.json | 11 ++++ src/test/vlog/parse_test/instance_test.v | 3 +- syntaxes/verilog.json | 66 ++++++++++++++++-------- 9 files changed, 121 insertions(+), 35 deletions(-) create mode 100644 src/test/.vscode/property.json diff --git a/resources/hdlParser/index.js b/resources/hdlParser/index.js index 2de23de..d042343 100644 --- a/resources/hdlParser/index.js +++ b/resources/hdlParser/index.js @@ -41,7 +41,7 @@ async function callParser(path, func) { const res = wasmModule.ccall('call_parser', 'string', ['string', 'int', 'int'], [file, fileLength, func]); debug.compute += Date.now() - s3; - console.log(debug); + console.log(path, debug); return JSON.parse(res); } diff --git a/src/extension.ts b/src/extension.ts index 317474a..3fbea3e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,10 +1,14 @@ import * as vscode from 'vscode'; +import * as fs from 'fs'; +import * as fspath from 'path'; -import { opeParam, MainOutput, ReportType } from './global'; +import { opeParam, MainOutput, ReportType, AbsPath } from './global'; import { hdlParam } from './hdlParser'; import * as manager from './manager'; import * as func from './function'; import { hdlMonitor } from './monitor'; +import { hdlPath } from './hdlFs'; +import { vlogFast } from '../resources/hdlParser'; async function registerCommand(context: vscode.ExtensionContext) { manager.registerManagerCommands(context); @@ -14,10 +18,46 @@ async function registerCommand(context: vscode.ExtensionContext) { func.registerToolCommands(context); } -async function launch(context: vscode.ExtensionContext) { +function* walk(path: AbsPath, ext: string): Generator { + if (fs.lstatSync(path).isFile()) { + if (path.endsWith(ext)) { + yield path; + } + } else { + for (const file of fs.readdirSync(path)) { + const stat = fs.lstatSync(path); + const filePath = fspath.join(path, file); + if (stat.isDirectory()) { + for (const targetPath of walk(filePath, ext)) { + yield targetPath; + } + } else if (stat.isFile()) { + if (filePath.endsWith(ext)) { + yield filePath; + } + } + } + } +} + + +async function test(context: vscode.ExtensionContext) { + if (vscode.workspace.workspaceFolders !== undefined && + vscode.workspace.workspaceFolders.length !== 0) { + const wsPath = hdlPath.toSlash(vscode.workspace.workspaceFolders[0].uri.fsPath); + for (const file of walk(wsPath, '.v')) { + if (typeof file === 'string') { + await vlogFast(file); + } + } + } +} + +async function launch(context: vscode.ExtensionContext) { await manager.prjManage.initialise(context); await registerCommand(context); hdlMonitor.start(); + // await vlogFast("e:/Project/Digial-IDE/TestWs/simulate/user/sim/tb_file/scc018ug_hd_rvt.v"); console.log(hdlParam); diff --git a/src/function/lsp/completion/vlog.ts b/src/function/lsp/completion/vlog.ts index 40eca88..da87e71 100644 --- a/src/function/lsp/completion/vlog.ts +++ b/src/function/lsp/completion/vlog.ts @@ -177,9 +177,9 @@ class VlogCompletionProvider implements vscode.CompletionItemProvider { const filePath = hdlPath.toSlash(document.fileName); // 1. provide keyword - const completions = this.makeKeywordItems(); - completions.push(...this.makeCompilerKeywordItems()); - completions.push(...this.makeSystemKeywordItems()); + const completions = this.makeKeywordItems(document, position); + completions.push(...this.makeCompilerKeywordItems(document, position)); + completions.push(...this.makeSystemKeywordItems(document, position)); const symbolResult = await HdlSymbol.all(filePath); if (!symbolResult) { @@ -222,7 +222,7 @@ class VlogCompletionProvider implements vscode.CompletionItemProvider { } } - private makeKeywordItems(): vscode.CompletionItem[] { + private makeKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { const vlogKeywordItem = []; for (const keyword of vlogKeyword.keys()) { const clItem = this.makekeywordCompletionItem(keyword); @@ -232,18 +232,21 @@ class VlogCompletionProvider implements vscode.CompletionItemProvider { return vlogKeywordItem; } - private makeCompilerKeywordItems(): vscode.CompletionItem[] { + private makeCompilerKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { const items = []; + const targetRange = document.getWordRangeAtPosition(position, /[`_0-9a-zA-Z]+/); + const targetWord = document.getText(targetRange); + const prefix = targetWord.startsWith('`') ? '' : '`'; for (const keyword of vlogKeyword.compilerKeys()) { const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword); - clItem.insertText = new vscode.SnippetString('`' + keyword); + clItem.insertText = new vscode.SnippetString(prefix + keyword); clItem.detail = 'compiler directive'; items.push(clItem); } return items; } - private makeSystemKeywordItems(): vscode.CompletionItem[] { + private makeSystemKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { const items = []; for (const keyword of vlogKeyword.systemKeys()) { const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Method); @@ -260,7 +263,8 @@ class VlogCompletionProvider implements vscode.CompletionItemProvider { clItem.detail = 'keyword'; switch (keyword) { - case 'begin': clItem.insertText = new vscode.SnippetString("begin$1end"); break; + case 'begin': clItem.insertText = new vscode.SnippetString("begin$1\nend"); break; + case 'function': clItem.insertText = new vscode.SnippetString("function ${1:name}\n\nendfunction"); break; default: break; } return clItem; diff --git a/src/function/lsp/hover/vlog.ts b/src/function/lsp/hover/vlog.ts index 5045cf3..7016703 100644 --- a/src/function/lsp/hover/vlog.ts +++ b/src/function/lsp/hover/vlog.ts @@ -158,6 +158,8 @@ class VlogHoverProvider implements vscode.HoverProvider { const normalResult = util.matchNormalSymbol(targetWord, scopeSymbols.symbols); if (normalResult) { const normalComment = await util.searchCommentAround(filePath, normalResult.range); + console.log(normalResult); + const normalDesc = util.makeNormalDesc(normalResult); content.appendCodeblock(normalDesc, HdlLangID.Verilog); diff --git a/src/function/lsp/util/index.ts b/src/function/lsp/util/index.ts index 06c264a..7dfc0fe 100644 --- a/src/function/lsp/util/index.ts +++ b/src/function/lsp/util/index.ts @@ -319,7 +319,11 @@ function makeParamDesc(param: HdlModuleParam): string { function makeNormalDesc(normal: RawSymbol): string { const width = normal.width ? normal.width : ''; - const desc = normal.type + ' ' + width + ' ' + normal.name; + const signed = normal.signed === 1 ? 'signed' : ''; + let desc = normal.type + ' ' + signed + ' ' + width + ' ' + normal.name; + if (normal.init) { + desc += ' = ' + normal.init; + } return desc; } diff --git a/src/hdlParser/common.ts b/src/hdlParser/common.ts index fa4385f..00d13af 100644 --- a/src/hdlParser/common.ts +++ b/src/hdlParser/common.ts @@ -165,6 +165,8 @@ interface RawSymbol { type: string range: Range width?: string + init?: string + signed: number }; interface InstModPathSearchResult { diff --git a/src/test/.vscode/property.json b/src/test/.vscode/property.json new file mode 100644 index 0000000..7dc2beb --- /dev/null +++ b/src/test/.vscode/property.json @@ -0,0 +1,11 @@ +{ + "toolChain": "xilinx", + "prjName": { + "PL": "template" + }, + "soc": { + "core": "none" + }, + "enableShowLog": false, + "device": "none" +} \ No newline at end of file diff --git a/src/test/vlog/parse_test/instance_test.v b/src/test/vlog/parse_test/instance_test.v index 613e852..cea48e2 100644 --- a/src/test/vlog/parse_test/instance_test.v +++ b/src/test/vlog/parse_test/instance_test.v @@ -1,3 +1,4 @@ +`include "./Cordic.v" module instance_test ( input input_a, input input_b, @@ -6,5 +7,5 @@ module instance_test ( assign output_c = input_a & input_b; - + endmodule \ No newline at end of file diff --git a/syntaxes/verilog.json b/syntaxes/verilog.json index 05073b1..0c2618c 100644 --- a/syntaxes/verilog.json +++ b/syntaxes/verilog.json @@ -7,38 +7,24 @@ "name": "Verilog", "patterns": [ { - "begin": "\\s*(wire|reg)\\s+\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "begin": "\\s*(wire|reg)\\s+(signed|unsigned)?\\s+\\[(.*?)(:)(.*?)\\]\\s+\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", "beginCaptures": { "1": { "name": "keyword.control.verilog" }, "2": { - "name": "variable.other.constant.declaration.verilog" - } - }, - "end": "(;)", - "endCaptures": { - "1": { - "name": "source.verilog" - } - } - }, - { - "begin": "\\s*(wire|reg)\\s+\\[(.*?)(:)(.*?)\\]\\s+\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", - "beginCaptures": { - "1": { "name": "keyword.control.verilog" }, - "2": { - "name": "constant.numeric.width.verilog" - }, "3": { - "name": "entity.name.function.width.spliter.verilog" - }, - "4": { "name": "constant.numeric.width.verilog" }, + "4": { + "name": "entity.name.function.width.spliter.verilog" + }, "5": { + "name": "constant.numeric.width.verilog" + }, + "6": { "name": "variable.other.constant.declaration.verilog" } }, @@ -47,7 +33,43 @@ "1": { "name": "source.verilog" } - } + }, + "patterns": [ + { + "include": "#constants" + }, + { + "include": "#operators" + } + ] + }, + { + "begin": "\\s*(wire|reg)\\s+(signed|unsigned)?\\s+\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.verilog" + }, + "2": { + "name": "keyword.control.verilog" + }, + "3": { + "name": "variable.other.constant.declaration.verilog" + } + }, + "end": "(;)", + "endCaptures": { + "1": { + "name": "source.verilog" + } + }, + "patterns": [ + { + "include": "#constants" + }, + { + "include": "#operators" + } + ] }, { "begin": "\\s*\\b(function|task)\\b(\\s+automatic)?",