完成打包

This commit is contained in:
锦恢 2024-10-09 18:01:27 +08:00
parent 22c6e4b0d9
commit 9418c8527e
21 changed files with 1324 additions and 1336 deletions

View File

@ -1,12 +1,12 @@
import { vlogCompletionProvider, vlogIncludeCompletionProvider, vlogMacroCompletionProvider, vlogPositionPortProvider } from './vlog'; // import { vlogCompletionProvider, vlogIncludeCompletionProvider, vlogMacroCompletionProvider, vlogPositionPortProvider } from './vlog';
import { vhdlCompletionProvider } from './vhdl'; // import { vhdlCompletionProvider } from './vhdl';
import { tclCompletionProvider } from './tcl'; import { tclCompletionProvider } from './tcl';
export { export {
vlogCompletionProvider, // vlogCompletionProvider,
vlogIncludeCompletionProvider, // vlogIncludeCompletionProvider,
vlogMacroCompletionProvider, // vlogMacroCompletionProvider,
vlogPositionPortProvider, // vlogPositionPortProvider,
vhdlCompletionProvider, // vhdlCompletionProvider,
tclCompletionProvider tclCompletionProvider
}; };

View File

@ -8,168 +8,167 @@ import { Define, Include, RawSymbol } from '../../../hdlParser/common';
import { HdlInstance, HdlModule } from '../../../hdlParser/core'; import { HdlInstance, HdlModule } from '../../../hdlParser/core';
import { vhdlKeyword } from '../util/keyword'; import { vhdlKeyword } from '../util/keyword';
import { hdlPath } from '../../../hdlFs'; import { hdlPath } from '../../../hdlFs';
import { hdlSymbolStorage } from '../core';
class VhdlCompletionProvider implements vscode.CompletionItemProvider { // class VhdlCompletionProvider implements vscode.CompletionItemProvider {
public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> { // public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> {
try { // try {
const filePath = hdlPath.toSlash(document.fileName); // const filePath = hdlPath.toSlash(document.fileName);
// 1. provide keyword // // 1. provide keyword
const completions = this.makeKeywordItems(document, position); // const completions = this.makeKeywordItems(document, position);
const symbolResult = await hdlSymbolStorage.getSymbol(filePath); // const symbolResult = await hdlSymbolStorage.getSymbol(filePath);
if (!symbolResult) { // if (!symbolResult) {
return completions; // return completions;
} // }
const symbols = symbolResult.content; // const symbols = symbolResult.content;
for (const symbol of symbols) { // for (const symbol of symbols) {
const kind = this.getCompletionItemKind(symbol.type); // const kind = this.getCompletionItemKind(symbol.type);
const clItem = new vscode.CompletionItem(symbol.name, kind); // const clItem = new vscode.CompletionItem(symbol.name, kind);
completions.push(clItem); // completions.push(clItem);
} // }
return completions; // return completions;
} catch (err) { // } catch (err) {
console.log(err); // console.log(err);
} // }
} // }
private getCompletionItemKind(type: string): vscode.CompletionItemKind { // private getCompletionItemKind(type: string): vscode.CompletionItemKind {
switch (type) { // switch (type) {
case 'entity': return vscode.CompletionItemKind.Class; break; // case 'entity': return vscode.CompletionItemKind.Class; break;
case 'port': return vscode.CompletionItemKind.Variable; break; // case 'port': return vscode.CompletionItemKind.Variable; break;
default: return vscode.CompletionItemKind.Value; break; // default: return vscode.CompletionItemKind.Value; break;
} // }
} // }
private makeKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { // private makeKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
const vhdlKeywordItems: vscode.CompletionItem[] = []; // const vhdlKeywordItems: vscode.CompletionItem[] = [];
for (const keyword of vhdlKeyword.keys()) { // for (const keyword of vhdlKeyword.keys()) {
const clItem = this.makekeywordCompletionItem(keyword, 'vhdl keyword'); // const clItem = this.makekeywordCompletionItem(keyword, 'vhdl keyword');
vhdlKeywordItems.push(clItem); // vhdlKeywordItems.push(clItem);
} // }
for (const keyword of vhdlKeyword.compilerKeys()) { // for (const keyword of vhdlKeyword.compilerKeys()) {
const clItem = this.makekeywordCompletionItem(keyword, 'IEEE lib function'); // const clItem = this.makekeywordCompletionItem(keyword, 'IEEE lib function');
vhdlKeywordItems.push(clItem); // vhdlKeywordItems.push(clItem);
} // }
for (const keyword of vhdlKeyword.systemKeys()) { // for (const keyword of vhdlKeyword.systemKeys()) {
const clItem = this.makekeywordCompletionItem(keyword, 'vhdl keyword'); // const clItem = this.makekeywordCompletionItem(keyword, 'vhdl keyword');
vhdlKeywordItems.push(clItem); // vhdlKeywordItems.push(clItem);
} // }
return vhdlKeywordItems; // return vhdlKeywordItems;
} // }
private makekeywordCompletionItem(keyword: string, detail: string): vscode.CompletionItem { // private makekeywordCompletionItem(keyword: string, detail: string): vscode.CompletionItem {
const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword); // const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword);
clItem.detail = detail; // clItem.detail = detail;
switch (keyword) { // switch (keyword) {
case 'begin': clItem.insertText = new vscode.SnippetString("begin$1\nend"); break; // case 'begin': clItem.insertText = new vscode.SnippetString("begin$1\nend"); break;
case 'entity': clItem.insertText = new vscode.SnippetString("entity ${1:name} is\n\t${2:content}\nend entity;"); break; // case 'entity': clItem.insertText = new vscode.SnippetString("entity ${1:name} is\n\t${2:content}\nend entity;"); break;
case 'architecture': clItem.insertText = new vscode.SnippetString("architecture ${1:name} of ${2:entity} is\n\t${3:definition}\nbegin\n\t${4:content}\nend architecture;"); break; // case 'architecture': clItem.insertText = new vscode.SnippetString("architecture ${1:name} of ${2:entity} is\n\t${3:definition}\nbegin\n\t${4:content}\nend architecture;"); break;
default: break; // default: break;
} // }
return clItem; // return clItem;
} // }
private async provideModules(document: vscode.TextDocument, position: vscode.Position, filePath: AbsPath, includes: Include[]): Promise<vscode.CompletionItem[]> { // private async provideModules(document: vscode.TextDocument, position: vscode.Position, filePath: AbsPath, includes: Include[]): Promise<vscode.CompletionItem[]> {
const suggestModules: vscode.CompletionItem[] = []; // const suggestModules: vscode.CompletionItem[] = [];
const lspVhdlConfig = vscode.workspace.getConfiguration('digital-ide.function.lsp.completion.vhdl'); // const lspVhdlConfig = vscode.workspace.getConfiguration('digital-ide.function.lsp.completion.vhdl');
const autoAddInclude: boolean = lspVhdlConfig.get('autoAddInclude', true); // const autoAddInclude: boolean = lspVhdlConfig.get('autoAddInclude', true);
const completeWholeInstante: boolean = lspVhdlConfig.get('completeWholeInstante', true); // const completeWholeInstante: boolean = lspVhdlConfig.get('completeWholeInstante', true);
const includePaths = new Set<AbsPath>(); // const includePaths = new Set<AbsPath>();
let lastIncludeLine = 0; // let lastIncludeLine = 0;
for (const include of includes) { // for (const include of includes) {
const absIncludePath = hdlPath.rel2abs(filePath, include.path); // const absIncludePath = hdlPath.rel2abs(filePath, include.path);
includePaths.add(absIncludePath); // includePaths.add(absIncludePath);
lastIncludeLine = Math.max(include.range.end.line, lastIncludeLine); // lastIncludeLine = Math.max(include.range.end.line, lastIncludeLine);
} // }
const insertPosition = new vscode.Position(lastIncludeLine, 0); // const insertPosition = new vscode.Position(lastIncludeLine, 0);
const insertRange = new vscode.Range(insertPosition, insertPosition); // const insertRange = new vscode.Range(insertPosition, insertPosition);
const fileFolder = hdlPath.resolve(filePath, '..'); // const fileFolder = hdlPath.resolve(filePath, '..');
// used only when completeWholeInstante is true // // used only when completeWholeInstante is true
let completePrefix = ''; // let completePrefix = '';
if (completeWholeInstante) { // if (completeWholeInstante) {
const wordRange = document.getWordRangeAtPosition(position); // const wordRange = document.getWordRangeAtPosition(position);
const countStart = wordRange ? wordRange.start.character : position.character; // const countStart = wordRange ? wordRange.start.character : position.character;
const spaceNumber = Math.floor(countStart / 4) * 4; // const spaceNumber = Math.floor(countStart / 4) * 4;
console.log(wordRange, countStart, spaceNumber); // console.log(wordRange, countStart, spaceNumber);
completePrefix = ' '.repeat(spaceNumber); // completePrefix = ' '.repeat(spaceNumber);
} // }
// for (const module of hdlParam.getAllHdlModules()) { // // for (const module of hdlParam.getAllHdlModules()) {
// const clItem = new vscode.CompletionItem(module.name, vscode.CompletionItemKind.Class); // // const clItem = new vscode.CompletionItem(module.name, vscode.CompletionItemKind.Class);
// // feature 1 : auto add include path if there's no corresponding include path // // // feature 1 : auto add include path if there's no corresponding include path
// if (autoAddInclude && !includePaths.has(module.path)) { // // if (autoAddInclude && !includePaths.has(module.path)) {
// const relPath: RelPath = hdlPath.relative(fileFolder, module.path); // // const relPath: RelPath = hdlPath.relative(fileFolder, module.path);
// const includeString = '`include "' + relPath + '"\n'; // // const includeString = '`include "' + relPath + '"\n';
// const textEdit = new vscode.TextEdit(insertRange, includeString); // // const textEdit = new vscode.TextEdit(insertRange, includeString);
// clItem.additionalTextEdits = [textEdit]; // // clItem.additionalTextEdits = [textEdit];
// } // // }
// // feature 2 : auto complete instance // // // feature 2 : auto complete instance
// if (completeWholeInstante) { // // if (completeWholeInstante) {
// const snippetString = instanceVhdlCode(module, '', true); // // const snippetString = instanceVhdlCode(module, '', true);
// clItem.insertText = new vscode.SnippetString(snippetString); // // clItem.insertText = new vscode.SnippetString(snippetString);
// } // // }
// clItem.detail = 'module'; // // clItem.detail = 'module';
// suggestModules.push(clItem); // // suggestModules.push(clItem);
// } // // }
return suggestModules; // return suggestModules;
} // }
private async provideParamsPorts(module: HdlModule): Promise<vscode.CompletionItem[]> { // private async provideParamsPorts(module: HdlModule): Promise<vscode.CompletionItem[]> {
if (!module) { // if (!module) {
return []; // return [];
} // }
const suggestParamsPorts = []; // const suggestParamsPorts = [];
for (const param of module.params) { // for (const param of module.params) {
const clItem = new vscode.CompletionItem(param.name, vscode.CompletionItemKind.Constant); // const clItem = new vscode.CompletionItem(param.name, vscode.CompletionItemKind.Constant);
clItem.detail = 'param'; // clItem.detail = 'param';
suggestParamsPorts.push(clItem); // suggestParamsPorts.push(clItem);
} // }
for (const port of module.ports) { // for (const port of module.ports) {
const clItem = new vscode.CompletionItem(port.name, vscode.CompletionItemKind.Interface); // const clItem = new vscode.CompletionItem(port.name, vscode.CompletionItemKind.Interface);
clItem.detail = 'port'; // clItem.detail = 'port';
suggestParamsPorts.push(clItem); // suggestParamsPorts.push(clItem);
} // }
return suggestParamsPorts; // return suggestParamsPorts;
} // }
private async provideNets(symbols: RawSymbol[]): Promise<vscode.CompletionItem[]> { // private async provideNets(symbols: RawSymbol[]): Promise<vscode.CompletionItem[]> {
if (!symbols) { // if (!symbols) {
return []; // return [];
} // }
const suggestNets = []; // const suggestNets = [];
for (const symbol of symbols) { // for (const symbol of symbols) {
if (symbol.type === 'wire' || symbol.type === 'reg') { // if (symbol.type === 'wire' || symbol.type === 'reg') {
const clItem = new vscode.CompletionItem(symbol.name, vscode.CompletionItemKind.Variable); // const clItem = new vscode.CompletionItem(symbol.name, vscode.CompletionItemKind.Variable);
clItem.sortText = ''; // clItem.sortText = '';
clItem.detail = symbol.type; // clItem.detail = symbol.type;
suggestNets.push(clItem); // suggestNets.push(clItem);
} // }
} // }
return suggestNets; // return suggestNets;
} // }
}; // };
const vhdlCompletionProvider = new VhdlCompletionProvider(); // const vhdlCompletionProvider = new VhdlCompletionProvider();
export { // export {
vhdlCompletionProvider // vhdlCompletionProvider
}; // };

View File

@ -9,383 +9,382 @@ import { Define, Include, RawSymbol } from '../../../hdlParser/common';
import { HdlInstance, HdlModule } from '../../../hdlParser/core'; import { HdlInstance, HdlModule } from '../../../hdlParser/core';
import { vlogKeyword } from '../util/keyword'; import { vlogKeyword } from '../util/keyword';
import { instanceVlogCode } from '../../sim/instance'; import { instanceVlogCode } from '../../sim/instance';
import { hdlSymbolStorage } from '../core';
// class VlogIncludeCompletionProvider implements vscode.CompletionItemProvider {
class VlogIncludeCompletionProvider implements vscode.CompletionItemProvider { // public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem>> {
public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem>> { // // console.log('VlogIncludeCompletionProvider');
// console.log('VlogIncludeCompletionProvider');
// try {
try { // const items = this.provideIncludeFiles(document, position);
const items = this.provideIncludeFiles(document, position); // return items;
return items; // } catch (err) {
} catch (err) { // console.log(err);
console.log(err); // }
} // }
}
// private provideIncludeFiles(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
private provideIncludeFiles(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { // if (position.character === 0) {
if (position.character === 0) { // return [];
return []; // }
} // const filePath = hdlPath.toSlash(document.fileName);
const filePath = hdlPath.toSlash(document.fileName); // const lineText = document.lineAt(position).text;
const lineText = document.lineAt(position).text;
// let firstQIndex = lineText.lastIndexOf('"', position.character - 1);
let firstQIndex = lineText.lastIndexOf('"', position.character - 1); // let lastQIndex = lineText.indexOf('"', position.character);
let lastQIndex = lineText.indexOf('"', position.character);
// if (firstQIndex !== -1 && lastQIndex !== -1) {
if (firstQIndex !== -1 && lastQIndex !== -1) { // const currentPath = lineText.substring(firstQIndex + 1, lastQIndex);
const currentPath = lineText.substring(firstQIndex + 1, lastQIndex); // const folderName = currentPath.length === 0 ? '.' : currentPath;
const folderName = currentPath.length === 0 ? '.' : currentPath; // const folderAbsPath = hdlPath.rel2abs(filePath, folderName);
const folderAbsPath = hdlPath.rel2abs(filePath, folderName); // return this.filterIncludeFiles(folderAbsPath, filePath);
return this.filterIncludeFiles(folderAbsPath, filePath); // }
}
// return [];
return []; // }
}
// private filterIncludeFiles(folderPath: AbsPath, currentPath: AbsPath) {
private filterIncludeFiles(folderPath: AbsPath, currentPath: AbsPath) { // if (fs.existsSync(folderPath)) {
if (fs.existsSync(folderPath)) { // const suggestFiles = [];
const suggestFiles = []; // for (const fileName of fs.readdirSync(folderPath)) {
for (const fileName of fs.readdirSync(folderPath)) { // const filePath = hdlPath.join(folderPath, fileName);
const filePath = hdlPath.join(folderPath, fileName); // if (filePath === currentPath) {
if (filePath === currentPath) { // continue;
continue; // }
}
// const stat = fs.statSync(filePath);
const stat = fs.statSync(filePath); // const clItem = new vscode.CompletionItem(fileName);
const clItem = new vscode.CompletionItem(fileName); // if (stat.isDirectory()) {
if (stat.isDirectory()) { // clItem.kind = vscode.CompletionItemKind.Folder;
clItem.kind = vscode.CompletionItemKind.Folder; // } else if (stat.isFile()) {
} else if (stat.isFile()) { // clItem.kind = vscode.CompletionItemKind.File;
clItem.kind = vscode.CompletionItemKind.File; // }
} // suggestFiles.push(clItem);
suggestFiles.push(clItem); // }
} // return suggestFiles;
return suggestFiles; // }
} // return [];
return []; // }
} // };
};
// class VlogMacroCompletionProvider implements vscode.CompletionItemProvider {
class VlogMacroCompletionProvider implements vscode.CompletionItemProvider { // public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> {
public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> { // // console.log('VlogMacroCompletionProvider');
// console.log('VlogMacroCompletionProvider');
// try {
try { // const targetWordRange = document.getWordRangeAtPosition(position, /[`_0-9a-zA-Z]+/);
const targetWordRange = document.getWordRangeAtPosition(position, /[`_0-9a-zA-Z]+/); // const targetWord = document.getText(targetWordRange);
const targetWord = document.getText(targetWordRange); // const filePath = document.fileName;
const filePath = document.fileName;
// const symbolResult = await hdlSymbolStorage.getSymbol(filePath);
const symbolResult = await hdlSymbolStorage.getSymbol(filePath); // if (!symbolResult) {
if (!symbolResult) { // return null;
return null; // }
}
// const items = this.provideMacros(targetWord, symbolResult.macro.defines);
const items = this.provideMacros(targetWord, symbolResult.macro.defines); // return items;
return items; // } catch (err) {
} catch (err) { // console.log(err);
console.log(err); // }
} // }
}
// private provideMacros(targetWord: string, defines: Define[]): vscode.CompletionItem[] {
private provideMacros(targetWord: string, defines: Define[]): vscode.CompletionItem[] { // const suggestMacros: vscode.CompletionItem[] = [];
const suggestMacros: vscode.CompletionItem[] = []; // if (!defines || defines.length === 0) {
if (!defines || defines.length === 0) { // return suggestMacros;
return suggestMacros; // }
} // for (const define of defines) {
for (const define of defines) { // const name = '`' + define.name;
const name = '`' + define.name; // const clItem = new vscode.CompletionItem(name, vscode.CompletionItemKind.Constant);
const clItem = new vscode.CompletionItem(name, vscode.CompletionItemKind.Constant); // clItem.detail = 'macro ' + define.replacement;
clItem.detail = 'macro ' + define.replacement; // clItem.insertText = targetWord.startsWith('`') ? define.name : name;
clItem.insertText = targetWord.startsWith('`') ? define.name : name; // suggestMacros.push(clItem);
suggestMacros.push(clItem); // }
} // return suggestMacros;
return suggestMacros; // }
} // }
}
// class VlogPositionPortProvider implements vscode.CompletionItemProvider {
class VlogPositionPortProvider implements vscode.CompletionItemProvider { // public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> {
public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> { // // console.log('enter VlogPositionPortProvider');
// console.log('enter VlogPositionPortProvider');
// try {
try { // const suggestPositionPorts: vscode.CompletionItem[] = [];
const suggestPositionPorts: vscode.CompletionItem[] = []; // const filePath = hdlPath.toSlash(document.fileName);
const filePath = hdlPath.toSlash(document.fileName); // const symbolResult = await hdlSymbolStorage.getSymbol(filePath);
const symbolResult = await hdlSymbolStorage.getSymbol(filePath);
// // console.log(symbolResult?.content);
// console.log(symbolResult?.content); // // console.log(position.character, position.line);
// console.log(position.character, position.line);
// if (!symbolResult) {
if (!symbolResult) { // return null;
return null; // }
}
// const scopeSymbols = util.locateVlogSymbol(position, symbolResult.content);
const scopeSymbols = util.locateVlogSymbol(position, symbolResult.content); // if (!scopeSymbols ||
if (!scopeSymbols || // !scopeSymbols.module ||
!scopeSymbols.module || // !scopeSymbols.symbols ||
!scopeSymbols.symbols || // !hdlParam.hasHdlModule(filePath, scopeSymbols.module.name)) {
!hdlParam.hasHdlModule(filePath, scopeSymbols.module.name)) { // return suggestPositionPorts;
return suggestPositionPorts; // }
}
// const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name);
const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name); // if (!currentModule) {
if (!currentModule) { // return;
return; // }
}
// const currentInst = util.filterInstanceByPosition(position, scopeSymbols.symbols, currentModule);
const currentInst = util.filterInstanceByPosition(position, scopeSymbols.symbols, currentModule); // // find instance and instMod is not null (solve the dependence already)
// find instance and instMod is not null (solve the dependence already)
// if (currentInst && currentInst.module && currentInst.instModPath) {
if (currentInst && currentInst.module && currentInst.instModPath) { // const portsparams = this.providePositionPorts(position, currentInst);
const portsparams = this.providePositionPorts(position, currentInst); // suggestPositionPorts.push(...portsparams);
suggestPositionPorts.push(...portsparams); // }
}
// return suggestPositionPorts;
return suggestPositionPorts;
// } catch (err) {
} catch (err) { // console.log(err);
console.log(err); // }
} // }
}
// private providePositionPorts(position: vscode.Position, currentInst: HdlInstance): vscode.CompletionItem[] {
private providePositionPorts(position: vscode.Position, currentInst: HdlInstance): vscode.CompletionItem[] { // if (!currentInst.module) {
if (!currentInst.module) { // return [];
return []; // }
}
// const params = currentInst.instparams;
const params = currentInst.instparams; // const ports = currentInst.instports;
const ports = currentInst.instports;
// if (params &&
if (params && // util.positionAfterEqual(position, params.start) &&
util.positionAfterEqual(position, params.start) && // util.positionAfterEqual(params.end, position)) {
util.positionAfterEqual(params.end, position)) {
// return currentInst.module.params.map(param => {
return currentInst.module.params.map(param => { // const clItem = new vscode.CompletionItem(param.name, vscode.CompletionItemKind.Constant);
const clItem = new vscode.CompletionItem(param.name, vscode.CompletionItemKind.Constant); // clItem.detail = 'param';
clItem.detail = 'param'; // return clItem;
return clItem; // });
}); // }
} // if (ports &&
if (ports && // util.positionAfterEqual(position, ports.start) &&
util.positionAfterEqual(position, ports.start) && // util.positionAfterEqual(ports.end, position)) {
util.positionAfterEqual(ports.end, position)) {
// return currentInst.module.ports.map(port => {
return currentInst.module.ports.map(port => { // const clItem = new vscode.CompletionItem(port.name, vscode.CompletionItemKind.Interface);
const clItem = new vscode.CompletionItem(port.name, vscode.CompletionItemKind.Interface); // clItem.detail = 'port';
clItem.detail = 'port'; // return clItem;
return clItem; // });
}); // }
}
// return [];
return []; // }
} // }
}
// class VlogCompletionProvider implements vscode.CompletionItemProvider {
class VlogCompletionProvider implements vscode.CompletionItemProvider { // public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> {
public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | vscode.CompletionList<vscode.CompletionItem> | null | undefined> { // // console.log('VlogCompletionProvider');
// console.log('VlogCompletionProvider');
// try {
try { // const filePath = hdlPath.toSlash(document.fileName);
const filePath = hdlPath.toSlash(document.fileName);
// // 1. provide keyword
// 1. provide keyword // const completions = this.makeKeywordItems(document, position);
const completions = this.makeKeywordItems(document, position); // completions.push(...this.makeCompilerKeywordItems(document, position));
completions.push(...this.makeCompilerKeywordItems(document, position)); // completions.push(...this.makeSystemKeywordItems(document, position));
completions.push(...this.makeSystemKeywordItems(document, position));
// const symbolResult = await hdlSymbolStorage.getSymbol(filePath);
const symbolResult = await hdlSymbolStorage.getSymbol(filePath); // if (!symbolResult) {
if (!symbolResult) { // return completions;
return completions; // }
}
// // locate at one module
// locate at one module // const scopeSymbols = util.locateVlogSymbol(position, symbolResult.content);
const scopeSymbols = util.locateVlogSymbol(position, symbolResult.content); // if (!scopeSymbols ||
if (!scopeSymbols || // !scopeSymbols.module ||
!scopeSymbols.module || // !hdlParam.hasHdlModule(filePath, scopeSymbols.module.name)) {
!hdlParam.hasHdlModule(filePath, scopeSymbols.module.name)) { // // MainOutput.report('Fail to get HdlModule ' + filePath + ' ' + scopeSymbols?.module.name, ReportType.Debug);
// MainOutput.report('Fail to get HdlModule ' + filePath + ' ' + scopeSymbols?.module.name, ReportType.Debug); // return completions;
return completions; // }
}
// // find wrapper module
// find wrapper module // const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name);
const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name); // if (!currentModule) {
if (!currentModule) { // return completions;
return completions; // }
}
// // 3. provide modules
// 3. provide modules // const suggestModulesPromise = this.provideModules(document, position, filePath, symbolResult.macro.includes);
const suggestModulesPromise = this.provideModules(document, position, filePath, symbolResult.macro.includes);
// // 4. provide params and ports of wrapper module
// 4. provide params and ports of wrapper module // const suggestParamsPortsPromise = this.provideParamsPorts(currentModule);
const suggestParamsPortsPromise = this.provideParamsPorts(currentModule);
// // 5. provide nets
// 5. provide nets // const suggestNetsPromise = this.provideNets(scopeSymbols.symbols);
const suggestNetsPromise = this.provideNets(scopeSymbols.symbols);
// // collect
// collect // completions.push(...await suggestModulesPromise);
completions.push(...await suggestModulesPromise); // completions.push(...await suggestParamsPortsPromise);
completions.push(...await suggestParamsPortsPromise); // completions.push(...await suggestNetsPromise);
completions.push(...await suggestNetsPromise);
// return completions;
return completions;
// } catch (err) {
} catch (err) { // console.log(err);
console.log(err); // }
} // }
}
// private makeKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
private makeKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { // const vlogKeywordItems: vscode.CompletionItem[] = [];
const vlogKeywordItems: vscode.CompletionItem[] = []; // for (const keyword of vlogKeyword.keys()) {
for (const keyword of vlogKeyword.keys()) { // const clItem = this.makekeywordCompletionItem(keyword);
const clItem = this.makekeywordCompletionItem(keyword); // vlogKeywordItems.push(clItem);
vlogKeywordItems.push(clItem); // }
}
// return vlogKeywordItems;
return vlogKeywordItems; // }
}
// private makeCompilerKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
private makeCompilerKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { // const items = [];
const items = []; // const targetRange = document.getWordRangeAtPosition(position, /[`_0-9a-zA-Z]+/);
const targetRange = document.getWordRangeAtPosition(position, /[`_0-9a-zA-Z]+/); // const targetWord = document.getText(targetRange);
const targetWord = document.getText(targetRange); // const prefix = targetWord.startsWith('`') ? '' : '`';
const prefix = targetWord.startsWith('`') ? '' : '`'; // for (const keyword of vlogKeyword.compilerKeys()) {
for (const keyword of vlogKeyword.compilerKeys()) { // const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword);
const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword); // clItem.insertText = new vscode.SnippetString(prefix + keyword);
clItem.insertText = new vscode.SnippetString(prefix + keyword); // clItem.detail = 'compiler directive';
clItem.detail = 'compiler directive'; // items.push(clItem);
items.push(clItem); // }
} // return items;
return items; // }
}
// private makeSystemKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
private makeSystemKeywordItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] { // const items = [];
const items = []; // for (const keyword of vlogKeyword.systemKeys()) {
for (const keyword of vlogKeyword.systemKeys()) { // const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Method);
const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Method); // clItem.insertText = new vscode.SnippetString('\\$' + keyword + '($1);');
clItem.insertText = new vscode.SnippetString('\\$' + keyword + '($1);'); // clItem.detail = 'system task';
clItem.detail = 'system task'; // items.push(clItem);
items.push(clItem); // }
} // return items;
return items; // }
}
// private makekeywordCompletionItem(keyword: string): vscode.CompletionItem {
private makekeywordCompletionItem(keyword: string): vscode.CompletionItem { // const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword);
const clItem = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword); // clItem.detail = 'verilog keyword';
clItem.detail = 'verilog keyword';
// switch (keyword) {
switch (keyword) { // case 'begin': clItem.insertText = new vscode.SnippetString("begin$1\nend"); 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;
case 'function': clItem.insertText = new vscode.SnippetString("function ${1:name}\n\nendfunction"); break; // default: break;
default: break; // }
} // return clItem;
return clItem; // }
}
// private async provideModules(document: vscode.TextDocument, position: vscode.Position, filePath: AbsPath, includes: Include[]): Promise<vscode.CompletionItem[]> {
private async provideModules(document: vscode.TextDocument, position: vscode.Position, filePath: AbsPath, includes: Include[]): Promise<vscode.CompletionItem[]> { // const suggestModules: vscode.CompletionItem[] = [];
const suggestModules: vscode.CompletionItem[] = [];
// const lspVlogConfig = vscode.workspace.getConfiguration('digital-ide.function.lsp.completion.vlog');
const lspVlogConfig = vscode.workspace.getConfiguration('digital-ide.function.lsp.completion.vlog'); // const autoAddInclude: boolean = lspVlogConfig.get('autoAddInclude', true);
const autoAddInclude: boolean = lspVlogConfig.get('autoAddInclude', true); // const completeWholeInstante: boolean = lspVlogConfig.get('completeWholeInstante', true);
const completeWholeInstante: boolean = lspVlogConfig.get('completeWholeInstante', true);
// const includePaths = new Set<AbsPath>();
const includePaths = new Set<AbsPath>(); // let lastIncludeLine = 0;
let lastIncludeLine = 0; // for (const include of includes) {
for (const include of includes) { // const absIncludePath = hdlPath.rel2abs(filePath, include.path);
const absIncludePath = hdlPath.rel2abs(filePath, include.path); // includePaths.add(absIncludePath);
includePaths.add(absIncludePath); // lastIncludeLine = Math.max(include.range.end.line, lastIncludeLine);
lastIncludeLine = Math.max(include.range.end.line, lastIncludeLine); // }
} // const insertPosition = new vscode.Position(lastIncludeLine, 0);
const insertPosition = new vscode.Position(lastIncludeLine, 0); // const insertRange = new vscode.Range(insertPosition, insertPosition);
const insertRange = new vscode.Range(insertPosition, insertPosition); // const fileFolder = hdlPath.resolve(filePath, '..');
const fileFolder = hdlPath.resolve(filePath, '..');
// // used only when completeWholeInstante is true
// used only when completeWholeInstante is true // let completePrefix = '';
let completePrefix = ''; // if (completeWholeInstante) {
if (completeWholeInstante) { // const wordRange = document.getWordRangeAtPosition(position);
const wordRange = document.getWordRangeAtPosition(position); // const countStart = wordRange ? wordRange.start.character : position.character;
const countStart = wordRange ? wordRange.start.character : position.character; // const spaceNumber = Math.floor(countStart / 4) * 4;
const spaceNumber = Math.floor(countStart / 4) * 4; // console.log(wordRange, countStart, spaceNumber);
console.log(wordRange, countStart, spaceNumber);
// completePrefix = ' '.repeat(spaceNumber);
completePrefix = ' '.repeat(spaceNumber); // }
}
// for (const module of hdlParam.getAllHdlModules()) {
for (const module of hdlParam.getAllHdlModules()) { // const clItem = new vscode.CompletionItem(module.name, vscode.CompletionItemKind.Class);
const clItem = new vscode.CompletionItem(module.name, vscode.CompletionItemKind.Class);
// // feature 1 : auto add include path if there's no corresponding include path
// feature 1 : auto add include path if there's no corresponding include path // if (autoAddInclude && !includePaths.has(module.path)) {
if (autoAddInclude && !includePaths.has(module.path)) { // const relPath: RelPath = hdlPath.relative(fileFolder, module.path);
const relPath: RelPath = hdlPath.relative(fileFolder, module.path); // const includeString = '`include "' + relPath + '"\n';
const includeString = '`include "' + relPath + '"\n'; // const textEdit = new vscode.TextEdit(insertRange, includeString);
const textEdit = new vscode.TextEdit(insertRange, includeString); // clItem.additionalTextEdits = [textEdit];
clItem.additionalTextEdits = [textEdit]; // }
}
// // feature 2 : auto complete instance
// feature 2 : auto complete instance // if (completeWholeInstante) {
if (completeWholeInstante) { // const snippetString = instanceVlogCode(module, '', true);
const snippetString = instanceVlogCode(module, '', true); // clItem.insertText = new vscode.SnippetString(snippetString);
clItem.insertText = new vscode.SnippetString(snippetString); // }
}
// clItem.detail = 'module';
clItem.detail = 'module'; // suggestModules.push(clItem);
suggestModules.push(clItem); // }
}
// return suggestModules;
return suggestModules; // }
}
// private async provideParamsPorts(module: HdlModule): Promise<vscode.CompletionItem[]> {
private async provideParamsPorts(module: HdlModule): Promise<vscode.CompletionItem[]> { // if (!module) {
if (!module) { // return [];
return []; // }
} // const suggestParamsPorts = [];
const suggestParamsPorts = []; // for (const param of module.params) {
for (const param of module.params) { // const clItem = new vscode.CompletionItem(param.name, vscode.CompletionItemKind.Constant);
const clItem = new vscode.CompletionItem(param.name, vscode.CompletionItemKind.Constant); // clItem.detail = 'param';
clItem.detail = 'param'; // suggestParamsPorts.push(clItem);
suggestParamsPorts.push(clItem); // }
}
// for (const port of module.ports) {
for (const port of module.ports) { // const clItem = new vscode.CompletionItem(port.name, vscode.CompletionItemKind.Interface);
const clItem = new vscode.CompletionItem(port.name, vscode.CompletionItemKind.Interface); // clItem.detail = 'port';
clItem.detail = 'port'; // suggestParamsPorts.push(clItem);
suggestParamsPorts.push(clItem); // }
}
// return suggestParamsPorts;
return suggestParamsPorts; // }
}
// private async provideNets(symbols: RawSymbol[]): Promise<vscode.CompletionItem[]> {
private async provideNets(symbols: RawSymbol[]): Promise<vscode.CompletionItem[]> { // if (!symbols) {
if (!symbols) { // return [];
return []; // }
} // const suggestNets = [];
const suggestNets = []; // for (const symbol of symbols) {
for (const symbol of symbols) { // if (symbol.type === 'wire' || symbol.type === 'reg') {
if (symbol.type === 'wire' || symbol.type === 'reg') { // const clItem = new vscode.CompletionItem(symbol.name, vscode.CompletionItemKind.Variable);
const clItem = new vscode.CompletionItem(symbol.name, vscode.CompletionItemKind.Variable); // clItem.sortText = '';
clItem.sortText = ''; // clItem.detail = symbol.type;
clItem.detail = symbol.type; // suggestNets.push(clItem);
suggestNets.push(clItem); // }
} // }
} // return suggestNets;
return suggestNets; // }
} // };
};
// const vlogCompletionProvider = new VlogCompletionProvider();
const vlogCompletionProvider = new VlogCompletionProvider(); // const vlogIncludeCompletionProvider = new VlogIncludeCompletionProvider();
const vlogIncludeCompletionProvider = new VlogIncludeCompletionProvider(); // const vlogMacroCompletionProvider = new VlogMacroCompletionProvider();
const vlogMacroCompletionProvider = new VlogMacroCompletionProvider(); // const vlogPositionPortProvider = new VlogPositionPortProvider();
const vlogPositionPortProvider = new VlogPositionPortProvider();
// export {
export { // vlogCompletionProvider,
vlogCompletionProvider, // vlogIncludeCompletionProvider,
vlogIncludeCompletionProvider, // vlogMacroCompletionProvider,
vlogMacroCompletionProvider, // vlogPositionPortProvider
vlogPositionPortProvider // };
};

View File

@ -1,7 +1,7 @@
import { vlogDefinitionProvider } from './vlog'; // import { vlogDefinitionProvider } from './vlog';
import { vhdlDefinitionProvider } from './vhdl'; // import { vhdlDefinitionProvider } from './vhdl';
export { export {
vlogDefinitionProvider, // vlogDefinitionProvider,
vhdlDefinitionProvider // vhdlDefinitionProvider
}; };

View File

@ -2,171 +2,169 @@ import * as vscode from 'vscode';
import { hdlPath } from '../../../hdlFs'; import { hdlPath } from '../../../hdlFs';
import { hdlParam } from '../../../hdlParser'; import { hdlParam } from '../../../hdlParser';
import { All } from '../../../../resources/hdlParser';
import { vlogKeyword } from '../util/keyword'; import { vlogKeyword } from '../util/keyword';
import * as util from '../util'; import * as util from '../util';
import { MainOutput, ReportType } from '../../../global'; import { MainOutput, ReportType } from '../../../global';
import { hdlSymbolStorage } from '../core';
import { RawSymbol } from '../../../hdlParser/common'; import { RawSymbol } from '../../../hdlParser/common';
class VhdlDefinitionProvider implements vscode.DefinitionProvider { // class VhdlDefinitionProvider implements vscode.DefinitionProvider {
public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Location | vscode.LocationLink[] | null> { // public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Location | vscode.LocationLink[] | null> {
// console.log('VhdlDefinitionProvider'); // // console.log('VhdlDefinitionProvider');
// get current words // // get current words
const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/); // const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/);
if (!wordRange) { // if (!wordRange) {
return null; // return null;
} // }
const targetWord = document.getText(wordRange); // const targetWord = document.getText(wordRange);
// check if need skip // // check if need skip
if (this.needSkip(document, position, targetWord)) { // if (this.needSkip(document, position, targetWord)) {
return null; // return null;
} // }
const filePath = document.fileName; // const filePath = document.fileName;
const vlogAll = await hdlSymbolStorage.getSymbol(filePath); // const vlogAll = await hdlSymbolStorage.getSymbol(filePath);
if (!vlogAll) { // if (!vlogAll) {
return null; // return null;
} else { // } else {
const location = await this.makeDefinition(document, position, vlogAll, targetWord, wordRange); // const location = await this.makeDefinition(document, position, vlogAll, targetWord, wordRange);
return location; // return location;
} // }
} // }
private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean { // private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean {
// check keyword // // check keyword
if (vlogKeyword.isKeyword(targetWord)) { // if (vlogKeyword.isKeyword(targetWord)) {
return true; // return true;
} // }
// TODO: check comment // // TODO: check comment
return false; // return false;
} // }
private async makeDefinition(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Location | vscode.LocationLink[] | null> { // private async makeDefinition(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Location | vscode.LocationLink[] | null> {
const filePath = hdlPath.toSlash(document.fileName); // const filePath = hdlPath.toSlash(document.fileName);
const lineText = document.lineAt(position).text; // const lineText = document.lineAt(position).text;
// locate at one entity or architecture // // locate at one entity or architecture
// TODO: remove it after adjust of backend // // TODO: remove it after adjust of backend
const rawSymbols = []; // const rawSymbols = [];
for (const symbol of all.content) { // for (const symbol of all.content) {
const rawSymbol: RawSymbol = { // const rawSymbol: RawSymbol = {
name: symbol.name, // name: symbol.name,
type: symbol.type, // type: symbol.type,
parent: symbol.parent, // parent: symbol.parent,
range: util.transformRange(symbol.range, -1), // range: util.transformRange(symbol.range, -1),
signed: symbol.signed, // signed: symbol.signed,
netType: symbol.netType // netType: symbol.netType
}; // };
rawSymbols.push(rawSymbol); // rawSymbols.push(rawSymbol);
} // }
const moduleScope = util.locateVhdlSymbol(position, rawSymbols); // const moduleScope = util.locateVhdlSymbol(position, rawSymbols);
if (!moduleScope) { // if (!moduleScope) {
return null; // return null;
} // }
const scopeType = moduleScope.module.type; // const scopeType = moduleScope.module.type;
if (scopeType === 'architecture') { // if (scopeType === 'architecture') {
return await this.makeArchitectureDefinition(filePath, targetWord, targetWordRange, moduleScope); // return await this.makeArchitectureDefinition(filePath, targetWord, targetWordRange, moduleScope);
} else if (scopeType === 'entity') { // } else if (scopeType === 'entity') {
return await this.makeEntityDefinition(filePath, targetWord, targetWordRange, moduleScope); // return await this.makeEntityDefinition(filePath, targetWord, targetWordRange, moduleScope);
} // }
return null; // return null;
} // }
private async makeArchitectureDefinition(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Location | vscode.LocationLink[] | null> { // private async makeArchitectureDefinition(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Location | vscode.LocationLink[] | null> {
const architecture = moduleScope.module; // const architecture = moduleScope.module;
// point to the entity of the architecture // // point to the entity of the architecture
if (architecture.parent && architecture.parent === targetWord) { // if (architecture.parent && architecture.parent === targetWord) {
const entity = hdlParam.getHdlModule(filePath, architecture.parent); // const entity = hdlParam.getHdlModule(filePath, architecture.parent);
if (entity) { // if (entity) {
const targetUri = vscode.Uri.file(entity.path); // const targetUri = vscode.Uri.file(entity.path);
const targetRange = util.transformRange(entity.range, -1, 0); // const targetRange = util.transformRange(entity.range, -1, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
} // }
// filter defined signal // // filter defined signal
for (const symbol of moduleScope.symbols) { // for (const symbol of moduleScope.symbols) {
if (symbol.name === targetWord) { // if (symbol.name === targetWord) {
const targetUri = vscode.Uri.file(filePath); // const targetUri = vscode.Uri.file(filePath);
const targetRange = util.transformRange(symbol.range, 0, 0); // const targetRange = util.transformRange(symbol.range, 0, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
} // }
// inner variable mapping to entity // // inner variable mapping to entity
if (architecture.parent) { // if (architecture.parent) {
const entity = hdlParam.getHdlModule(filePath, architecture.parent); // const entity = hdlParam.getHdlModule(filePath, architecture.parent);
if (entity) { // if (entity) {
// find params definitio // // find params definitio
for (const param of entity.params) { // for (const param of entity.params) {
if (param.name === targetWord) { // if (param.name === targetWord) {
const targetUri = vscode.Uri.file(entity.path); // const targetUri = vscode.Uri.file(entity.path);
const targetRange = util.transformRange(param.range, -1, 0); // const targetRange = util.transformRange(param.range, -1, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
} // }
// find ports definition // // find ports definition
for (const port of entity.ports) { // for (const port of entity.ports) {
if (port.name === targetWord) { // if (port.name === targetWord) {
const targetUri = vscode.Uri.file(entity.path); // const targetUri = vscode.Uri.file(entity.path);
const targetRange = util.transformRange(port.range, -1, 0); // const targetRange = util.transformRange(port.range, -1, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
} // }
} // }
} // }
return null; // return null;
} // }
private async makeEntityDefinition(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Location | vscode.LocationLink[] | null> { // private async makeEntityDefinition(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Location | vscode.LocationLink[] | null> {
const entity = hdlParam.getHdlModule(filePath, moduleScope.module.name); // const entity = hdlParam.getHdlModule(filePath, moduleScope.module.name);
if (entity) { // if (entity) {
if (targetWord === entity.name) { // if (targetWord === entity.name) {
const targetUri = vscode.Uri.file(entity.path); // const targetUri = vscode.Uri.file(entity.path);
const targetRange = util.transformRange(entity.range, -1, 0); // const targetRange = util.transformRange(entity.range, -1, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
// find params definitio // // find params definitio
for (const param of entity.params) { // for (const param of entity.params) {
if (param.name === targetWord) { // if (param.name === targetWord) {
const targetUri = vscode.Uri.file(entity.path); // const targetUri = vscode.Uri.file(entity.path);
const targetRange = util.transformRange(param.range, -1, 0); // const targetRange = util.transformRange(param.range, -1, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
} // }
// find ports definition // // find ports definition
for (const port of entity.ports) { // for (const port of entity.ports) {
if (port.name === targetWord) { // if (port.name === targetWord) {
const targetUri = vscode.Uri.file(entity.path); // const targetUri = vscode.Uri.file(entity.path);
const targetRange = util.transformRange(port.range, -1, 0); // const targetRange = util.transformRange(port.range, -1, 0);
const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri, targetRange, originSelectionRange: targetWordRange };
return [ link ]; // return [ link ];
} // }
} // }
} // }
return null; // return null;
} // }
} // }
const vhdlDefinitionProvider = new VhdlDefinitionProvider(); // const vhdlDefinitionProvider = new VhdlDefinitionProvider();
export { // export {
vhdlDefinitionProvider // vhdlDefinitionProvider
}; // };

View File

@ -2,162 +2,160 @@ import * as vscode from 'vscode';
import { hdlPath } from '../../../hdlFs'; import { hdlPath } from '../../../hdlFs';
import { hdlParam } from '../../../hdlParser'; import { hdlParam } from '../../../hdlParser';
import { All } from '../../../../resources/hdlParser';
import { vlogKeyword } from '../util/keyword'; import { vlogKeyword } from '../util/keyword';
import * as util from '../util'; import * as util from '../util';
import { MainOutput, ReportType } from '../../../global'; import { MainOutput, ReportType } from '../../../global';
import { hdlSymbolStorage } from '../core';
class VlogDefinitionProvider implements vscode.DefinitionProvider { // class VlogDefinitionProvider implements vscode.DefinitionProvider {
public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Location | vscode.LocationLink[] | null> { // public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Location | vscode.LocationLink[] | null> {
// console.log('VlogDefinitionProvider'); // // console.log('VlogDefinitionProvider');
// get current words // // get current words
const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/); // const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/);
if (!wordRange) { // if (!wordRange) {
return null; // return null;
} // }
const targetWord = document.getText(wordRange); // const targetWord = document.getText(wordRange);
// check if need skip // // check if need skip
if (this.needSkip(document, position, targetWord)) { // if (this.needSkip(document, position, targetWord)) {
return null; // return null;
} // }
const filePath = document.fileName; // const filePath = document.fileName;
const vlogAll = await hdlSymbolStorage.getSymbol(filePath); // const vlogAll = await hdlSymbolStorage.getSymbol(filePath);
if (!vlogAll) { // if (!vlogAll) {
return null; // return null;
} else { // } else {
const location = await this.makeDefinition(document, position, vlogAll, targetWord, wordRange); // const location = await this.makeDefinition(document, position, vlogAll, targetWord, wordRange);
return location; // return location;
} // }
} // }
private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean { // private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean {
// check keyword // // check keyword
if (vlogKeyword.isKeyword(targetWord)) { // if (vlogKeyword.isKeyword(targetWord)) {
return true; // return true;
} // }
// TODO: check comment // // TODO: check comment
return false; // return false;
} // }
private async makeDefinition(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Location | vscode.LocationLink[] | null> { // private async makeDefinition(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Location | vscode.LocationLink[] | null> {
const filePath = hdlPath.toSlash(document.fileName); // const filePath = hdlPath.toSlash(document.fileName);
const lineText = document.lineAt(position).text; // const lineText = document.lineAt(position).text;
// match `include // // match `include
const includeResult = util.matchInclude(document, position, all.macro.includes); // const includeResult = util.matchInclude(document, position, all.macro.includes);
if (includeResult) { // if (includeResult) {
const absPath = hdlPath.rel2abs(filePath, includeResult.name); // const absPath = hdlPath.rel2abs(filePath, includeResult.name);
const targetFile = vscode.Uri.file(absPath); // const targetFile = vscode.Uri.file(absPath);
const targetPosition = new vscode.Position(0, 0); // const targetPosition = new vscode.Position(0, 0);
const targetRange = new vscode.Range(targetPosition, targetPosition); // const targetRange = new vscode.Range(targetPosition, targetPosition);
const originSelectionRange = document.getWordRangeAtPosition(position, /["\.\\\/_0-9A-Za-z]+/); // const originSelectionRange = document.getWordRangeAtPosition(position, /["\.\\\/_0-9A-Za-z]+/);
const link: vscode.LocationLink = { targetUri: targetFile, targetRange, originSelectionRange }; // const link: vscode.LocationLink = { targetUri: targetFile, targetRange, originSelectionRange };
return [link]; // return [link];
} // }
// match macro // // match macro
const macroResult = util.matchDefineMacro(position, targetWord, all.macro.defines); // const macroResult = util.matchDefineMacro(position, targetWord, all.macro.defines);
if (macroResult) { // if (macroResult) {
const targetRange = util.transformRange(macroResult.range, -1, -1); // const targetRange = util.transformRange(macroResult.range, -1, -1);
const link: vscode.LocationLink = { targetUri: document.uri, targetRange: targetRange, originSelectionRange: targetWordRange }; // const link: vscode.LocationLink = { targetUri: document.uri, targetRange: targetRange, originSelectionRange: targetWordRange };
return [link]; // return [link];
} // }
// locate at one module // // locate at one module
const scopeSymbols = util.locateVlogSymbol(position, all.content); // const scopeSymbols = util.locateVlogSymbol(position, all.content);
if (!scopeSymbols || !scopeSymbols.module) { // if (!scopeSymbols || !scopeSymbols.module) {
return null; // return null;
} // }
const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name); // const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name);
if (!currentModule) { // if (!currentModule) {
MainOutput.report('Fail to get HdlModule ' + filePath + ' ' + scopeSymbols.module.name, ReportType.Debug); // MainOutput.report('Fail to get HdlModule ' + filePath + ' ' + scopeSymbols.module.name, ReportType.Debug);
return null; // return null;
} // }
// match instance // // match instance
const instResult = util.matchInstance(targetWord, currentModule); // const instResult = util.matchInstance(targetWord, currentModule);
if (instResult) { // if (instResult) {
const instModule = instResult.module; // const instModule = instResult.module;
if (!instModule || !instResult.instModPath) { // if (!instModule || !instResult.instModPath) {
return null; // return null;
} // }
const targetFile = vscode.Uri.file(instResult.instModPath); // const targetFile = vscode.Uri.file(instResult.instModPath);
const targetRange = util.transformRange(instModule.range, -1, 0, 1); // const targetRange = util.transformRange(instModule.range, -1, 0, 1);
const link: vscode.LocationLink = { targetUri: targetFile, targetRange }; // const link: vscode.LocationLink = { targetUri: targetFile, targetRange };
return [link]; // return [link];
} // }
// match port or param definition (position input) // // match port or param definition (position input)
if (util.isPositionInput(lineText, position.character)) { // if (util.isPositionInput(lineText, position.character)) {
const currentInstResult = util.filterInstanceByPosition(position, scopeSymbols.symbols, currentModule); // const currentInstResult = util.filterInstanceByPosition(position, scopeSymbols.symbols, currentModule);
if (!currentInstResult || !currentInstResult.instModPath) { // if (!currentInstResult || !currentInstResult.instModPath) {
return null; // return null;
} // }
const instParamPromise = util.getInstParamByPosition(currentInstResult, position, targetWord); // const instParamPromise = util.getInstParamByPosition(currentInstResult, position, targetWord);
const instPortPromise = util.getInstPortByPosition(currentInstResult, position, targetWord); // const instPortPromise = util.getInstPortByPosition(currentInstResult, position, targetWord);
const instParam = await instParamPromise; // const instParam = await instParamPromise;
const instPort = await instPortPromise; // const instPort = await instPortPromise;
const instModPathUri = vscode.Uri.file(currentInstResult.instModPath); // const instModPathUri = vscode.Uri.file(currentInstResult.instModPath);
if (instParam) { // if (instParam) {
const targetRange = util.transformRange(instParam.range, -1, 0); // const targetRange = util.transformRange(instParam.range, -1, 0);
const link: vscode.LocationLink = { targetUri: instModPathUri, targetRange }; // const link: vscode.LocationLink = { targetUri: instModPathUri, targetRange };
return [link]; // return [link];
} // }
if (instPort) { // if (instPort) {
const targetRange = util.transformRange(instPort.range, -1, 0); // const targetRange = util.transformRange(instPort.range, -1, 0);
const link: vscode.LocationLink = { targetUri: instModPathUri, targetRange }; // const link: vscode.LocationLink = { targetUri: instModPathUri, targetRange };
return [link]; // return [link];
} // }
return null; // return null;
} // }
// match params // // match params
const paramResult = util.matchParams(targetWord, currentModule); // const paramResult = util.matchParams(targetWord, currentModule);
if (paramResult) { // if (paramResult) {
const targetRange = util.transformRange(paramResult.range, -1, 0); // const targetRange = util.transformRange(paramResult.range, -1, 0);
const link: vscode.LocationLink = { targetUri: document.uri, targetRange }; // const link: vscode.LocationLink = { targetUri: document.uri, targetRange };
return [link]; // return [link];
} // }
// match ports // // match ports
const portResult = util.matchPorts(targetWord, currentModule); // const portResult = util.matchPorts(targetWord, currentModule);
if (portResult) { // if (portResult) {
const targetRange = util.transformRange(portResult.range, -1, 0); // const targetRange = util.transformRange(portResult.range, -1, 0);
const link: vscode.LocationLink = { targetUri: document.uri, targetRange }; // const link: vscode.LocationLink = { targetUri: document.uri, targetRange };
return [link]; // return [link];
} // }
// match others // // match others
const normalResult = util.matchNormalSymbol(targetWord, scopeSymbols.symbols); // const normalResult = util.matchNormalSymbol(targetWord, scopeSymbols.symbols);
if (normalResult) { // if (normalResult) {
const targetRange = util.transformRange(normalResult.range, -1, 0); // const targetRange = util.transformRange(normalResult.range, -1, 0);
const link: vscode.LocationLink = { targetUri: document.uri, targetRange }; // const link: vscode.LocationLink = { targetUri: document.uri, targetRange };
return [link]; // return [link];
} // }
return null; // return null;
} // }
} // }
const vlogDefinitionProvider = new VlogDefinitionProvider(); // const vlogDefinitionProvider = new VlogDefinitionProvider();
export { // export {
vlogDefinitionProvider // vlogDefinitionProvider
}; // };

View File

@ -1,6 +1,6 @@
import { vlogDocSenmanticProvider, vlogLegend } from './vlog'; // import { vlogDocSenmanticProvider, vlogLegend } from './vlog';
export { // export {
vlogDocSenmanticProvider, // vlogDocSenmanticProvider,
vlogLegend // vlogLegend
}; // };

View File

@ -1,7 +1,4 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { All } from '../../../../resources/hdlParser';
import { HdlSymbol } from '../../../hdlParser';
import { hdlSymbolStorage } from '../core';
import { transformRange } from '../util'; import { transformRange } from '../util';
const tokenTypes = ['class', 'function', 'variable']; const tokenTypes = ['class', 'function', 'variable'];
@ -9,44 +6,44 @@ const tokenModifiers = ['declaration', 'documentation'];
const vlogLegend = new vscode.SemanticTokensLegend(tokenTypes, tokenModifiers); const vlogLegend = new vscode.SemanticTokensLegend(tokenTypes, tokenModifiers);
class VlogDocSenmanticProvider implements vscode.DocumentSemanticTokensProvider { // class VlogDocSenmanticProvider implements vscode.DocumentSemanticTokensProvider {
public async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens | null | undefined> { // public async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens | null | undefined> {
// TODO : finish this // // TODO : finish this
const tokensBuilder = new vscode.SemanticTokensBuilder(vlogLegend); // const tokensBuilder = new vscode.SemanticTokensBuilder(vlogLegend);
return tokensBuilder.build(); // return tokensBuilder.build();
} // }
private prepareTokensBuilder(builder: vscode.SemanticTokensBuilder, all: All){ // private prepareTokensBuilder(builder: vscode.SemanticTokensBuilder, all: All){
for (const rawSymbol of all.content) { // for (const rawSymbol of all.content) {
const semanticRange = transformRange(rawSymbol.range, -1, 0); // const semanticRange = transformRange(rawSymbol.range, -1, 0);
const tokenType = this.getTokenTypes(rawSymbol.type); // const tokenType = this.getTokenTypes(rawSymbol.type);
if (tokenType) { // if (tokenType) {
builder.push(semanticRange, tokenType); // builder.push(semanticRange, tokenType);
} // }
} // }
} // }
private getTokenTypes(type: string): string | undefined { // private getTokenTypes(type: string): string | undefined {
switch (type) { // switch (type) {
case 'input': // case 'input':
return 'variable'; // return 'variable';
case 'output': // case 'output':
return 'variable'; // return 'variable';
case 'wire': // case 'wire':
return 'variable'; // return 'variable';
case 'reg': // case 'reg':
return 'variable'; // return 'variable';
default: // default:
return; // return;
} // }
} // }
} // }
const vlogDocSenmanticProvider = new VlogDocSenmanticProvider(); // const vlogDocSenmanticProvider = new VlogDocSenmanticProvider();
export { // export {
vlogDocSenmanticProvider, // vlogDocSenmanticProvider,
vlogLegend // vlogLegend
}; // };

View File

@ -1,8 +1,8 @@
import { vlogDocSymbolProvider } from './vlog'; // import { vlogDocSymbolProvider } from './vlog';
import { vhdlDocSymbolProvider } from './vhdl'; // import { vhdlDocSymbolProvider } from './vhdl';
export { // export {
vlogDocSymbolProvider, // vlogDocSymbolProvider,
vhdlDocSymbolProvider // vhdlDocSymbolProvider
}; // };

View File

@ -2,85 +2,84 @@ import * as vscode from 'vscode';
import { AllowNull } from '../../../global'; import { AllowNull } from '../../../global';
import { RawSymbol, Range } from '../../../hdlParser/common'; import { RawSymbol, Range } from '../../../hdlParser/common';
import { hdlSymbolStorage } from '../core';
interface DocSymbolContainer { // interface DocSymbolContainer {
docSymbol: AllowNull<vscode.DocumentSymbol>, // docSymbol: AllowNull<vscode.DocumentSymbol>,
range: AllowNull<Range> // range: AllowNull<Range>
}; // };
const vhdlSymbolKind: Record<string, vscode.SymbolKind> = { // const vhdlSymbolKind: Record<string, vscode.SymbolKind> = {
entity: vscode.SymbolKind.Interface, // entity: vscode.SymbolKind.Interface,
port: vscode.SymbolKind.Property, // port: vscode.SymbolKind.Property,
architecture: vscode.SymbolKind.Variable, // architecture: vscode.SymbolKind.Variable,
signal: vscode.SymbolKind.Property // signal: vscode.SymbolKind.Property
}; // };
class VhdlDocSymbolProvider implements vscode.DocumentSymbolProvider { // class VhdlDocSymbolProvider implements vscode.DocumentSymbolProvider {
public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[]> { // public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[]> {
const path = document.fileName; // const path = document.fileName;
const vhdlAll = await hdlSymbolStorage.getSymbol(path); // const vhdlAll = await hdlSymbolStorage.getSymbol(path);
if (!vhdlAll || !vhdlAll.content) { // if (!vhdlAll || !vhdlAll.content) {
return []; // return [];
} else { // } else {
const symbols = vhdlAll.content; // const symbols = vhdlAll.content;
const symbolInfos = this.makeDocumentSymbols(document, symbols); // const symbolInfos = this.makeDocumentSymbols(document, symbols);
return symbolInfos; // return symbolInfos;
} // }
} // }
private makeDocumentSymbols(document: vscode.TextDocument, symbols: RawSymbol[]): vscode.DocumentSymbol[] { // private makeDocumentSymbols(document: vscode.TextDocument, symbols: RawSymbol[]): vscode.DocumentSymbol[] {
const docSymbols: vscode.DocumentSymbol[] = []; // const docSymbols: vscode.DocumentSymbol[] = [];
for (const symbol of symbols) { // for (const symbol of symbols) {
const symbolStart = new vscode.Position(symbol.range.start.line - 1, symbol.range.start.character); // const symbolStart = new vscode.Position(symbol.range.start.line - 1, symbol.range.start.character);
const symbolEnd = new vscode.Position(symbol.range.end.line - 1, symbol.range.end.character); // const symbolEnd = new vscode.Position(symbol.range.end.line - 1, symbol.range.end.character);
const symbolRange = new vscode.Range(symbolStart, symbolEnd); // const symbolRange = new vscode.Range(symbolStart, symbolEnd);
if (symbol.type === 'entity') { // if (symbol.type === 'entity') {
const docSymbol = new vscode.DocumentSymbol(symbol.name, // const docSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.name, // symbol.name,
vhdlSymbolKind[symbol.type], // vhdlSymbolKind[symbol.type],
symbolRange, // symbolRange,
symbolRange); // symbolRange);
docSymbols.push(docSymbol); // docSymbols.push(docSymbol);
} else if (symbol.type === 'port') { // } else if (symbol.type === 'port') {
const parentEntity = docSymbols[docSymbols.length - 1]; // const parentEntity = docSymbols[docSymbols.length - 1];
const docSymbol = new vscode.DocumentSymbol(symbol.name, // const docSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.name, // symbol.name,
vhdlSymbolKind[symbol.type], // vhdlSymbolKind[symbol.type],
symbolRange, // symbolRange,
symbolRange); // symbolRange);
parentEntity.children.push(docSymbol); // parentEntity.children.push(docSymbol);
} else if (symbol.type === 'architecture') { // } else if (symbol.type === 'architecture') {
const docSymbol = new vscode.DocumentSymbol(symbol.name, // const docSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.name, // symbol.name,
vhdlSymbolKind[symbol.type], // vhdlSymbolKind[symbol.type],
symbolRange, // symbolRange,
symbolRange); // symbolRange);
docSymbols.push(docSymbol); // docSymbols.push(docSymbol);
} else if (symbol.type === 'signal') { // } else if (symbol.type === 'signal') {
const parentArchitecture = docSymbols[docSymbols.length - 1]; // const parentArchitecture = docSymbols[docSymbols.length - 1];
if (parentArchitecture.kind === vhdlSymbolKind['architecture']) { // if (parentArchitecture.kind === vhdlSymbolKind['architecture']) {
const docSymbol = new vscode.DocumentSymbol(symbol.name, // const docSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.name, // symbol.name,
vhdlSymbolKind[symbol.type], // vhdlSymbolKind[symbol.type],
symbolRange, // symbolRange,
symbolRange); // symbolRange);
parentArchitecture.children.push(docSymbol); // parentArchitecture.children.push(docSymbol);
} // }
} // }
} // }
return docSymbols; // return docSymbols;
} // }
} // }
const vhdlDocSymbolProvider = new VhdlDocSymbolProvider(); // const vhdlDocSymbolProvider = new VhdlDocSymbolProvider();
export { // export {
vhdlDocSymbolProvider // vhdlDocSymbolProvider
}; // };

View File

@ -2,191 +2,190 @@ import * as vscode from 'vscode';
import { AllowNull } from '../../../global'; import { AllowNull } from '../../../global';
import { RawSymbol, Range } from '../../../hdlParser/common'; import { RawSymbol, Range } from '../../../hdlParser/common';
import { hdlSymbolStorage } from '../core';
import { positionAfterEqual } from '../util'; import { positionAfterEqual } from '../util';
interface DocSymbolContainer { // interface DocSymbolContainer {
docSymbol: AllowNull<vscode.DocumentSymbol>, // docSymbol: AllowNull<vscode.DocumentSymbol>,
range: AllowNull<Range> // range: AllowNull<Range>
}; // };
class VlogDocSymbolProvider implements vscode.DocumentSymbolProvider { // class VlogDocSymbolProvider implements vscode.DocumentSymbolProvider {
public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[]> { // public async provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[]> {
// console.log('VlogDocSymbolProvider'); // // console.log('VlogDocSymbolProvider');
const path = document.fileName; // const path = document.fileName;
const vlogAll = await hdlSymbolStorage.getSymbol(path); // const vlogAll = await hdlSymbolStorage.getSymbol(path);
if (!vlogAll || !vlogAll.content) { // if (!vlogAll || !vlogAll.content) {
return []; // return [];
} else { // } else {
const symbols = vlogAll.content; // const symbols = vlogAll.content;
const symbolInfos = this.makeDocumentSymbols(document, symbols); // const symbolInfos = this.makeDocumentSymbols(document, symbols);
return symbolInfos; // return symbolInfos;
} // }
} // }
private makeDocumentSymbols(document: vscode.TextDocument, symbols: RawSymbol[]): vscode.DocumentSymbol[] { // private makeDocumentSymbols(document: vscode.TextDocument, symbols: RawSymbol[]): vscode.DocumentSymbol[] {
const docSymbols = []; // const docSymbols = [];
const visitedSymbols = new Set(); // const visitedSymbols = new Set();
const moduleSymbols = symbols.filter(symbol => { // const moduleSymbols = symbols.filter(symbol => {
if (symbol.type === 'module') { // if (symbol.type === 'module') {
visitedSymbols.add(symbol); // visitedSymbols.add(symbol);
return true; // return true;
} // }
return false; // return false;
}); // });
for (const moduleSymbol of moduleSymbols) { // for (const moduleSymbol of moduleSymbols) {
const moduleName = moduleSymbol.name; // const moduleName = moduleSymbol.name;
const moduleKind = this.getSymbolKind(moduleSymbol.type); // const moduleKind = this.getSymbolKind(moduleSymbol.type);
const moduleStart = new vscode.Position(moduleSymbol.range.start.line - 1, moduleSymbol.range.start.character); // const moduleStart = new vscode.Position(moduleSymbol.range.start.line - 1, moduleSymbol.range.start.character);
const moduleEnd = new vscode.Position(moduleSymbol.range.end.line - 1, moduleSymbol.range.start.character); // const moduleEnd = new vscode.Position(moduleSymbol.range.end.line - 1, moduleSymbol.range.start.character);
const moduleRange = new vscode.Range(moduleStart, moduleEnd); // const moduleRange = new vscode.Range(moduleStart, moduleEnd);
const moduleDocSymbol = new vscode.DocumentSymbol(moduleName, // const moduleDocSymbol = new vscode.DocumentSymbol(moduleName,
moduleName, // moduleName,
moduleKind, // moduleKind,
moduleRange, // moduleRange,
moduleRange); // moduleRange);
docSymbols.push(moduleDocSymbol); // docSymbols.push(moduleDocSymbol);
const paramContainer: DocSymbolContainer = { // const paramContainer: DocSymbolContainer = {
docSymbol: null, // docSymbol: null,
range: null // range: null
}; // };
const portContainer: DocSymbolContainer = { // const portContainer: DocSymbolContainer = {
docSymbol: null, // docSymbol: null,
range: null // range: null
}; // };
const portTypes = ['input', 'inout', 'output']; // const portTypes = ['input', 'inout', 'output'];
// make others in module inner // // make others in module inner
for (const symbol of symbols) { // for (const symbol of symbols) {
if (visitedSymbols.has(symbol)) { // if (visitedSymbols.has(symbol)) {
continue; // continue;
} // }
if (!(positionAfterEqual(symbol.range.start, moduleSymbol.range.start) && // if (!(positionAfterEqual(symbol.range.start, moduleSymbol.range.start) &&
positionAfterEqual(moduleSymbol.range.end, symbol.range.end))) { // positionAfterEqual(moduleSymbol.range.end, symbol.range.end))) {
continue; // continue;
} // }
if (!symbol.name) { // if (!symbol.name) {
symbol.name = '???'; // symbol.name = '???';
} // }
visitedSymbols.add(symbol); // visitedSymbols.add(symbol);
const symbolStart = new vscode.Position(symbol.range.start.line - 1, symbol.range.start.character); // const symbolStart = new vscode.Position(symbol.range.start.line - 1, symbol.range.start.character);
const symbolEnd = new vscode.Position(symbol.range.end.line - 1, symbol.range.end.character); // const symbolEnd = new vscode.Position(symbol.range.end.line - 1, symbol.range.end.character);
const symbolRange = new vscode.Range(symbolStart, symbolEnd); // const symbolRange = new vscode.Range(symbolStart, symbolEnd);
if (symbol.type === 'parameter') { // if (symbol.type === 'parameter') {
if (!paramContainer.range) { // if (!paramContainer.range) {
paramContainer.range = symbolRange; // paramContainer.range = symbolRange;
paramContainer.docSymbol = new vscode.DocumentSymbol('param', // paramContainer.docSymbol = new vscode.DocumentSymbol('param',
'param description', // 'param description',
vscode.SymbolKind.Method, // vscode.SymbolKind.Method,
symbolRange, // symbolRange,
symbolRange); // symbolRange);
moduleDocSymbol.children.push(paramContainer.docSymbol); // moduleDocSymbol.children.push(paramContainer.docSymbol);
} // }
const paramDocSymbol = new vscode.DocumentSymbol(symbol.name, // const paramDocSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.type, // symbol.type,
vscode.SymbolKind.Constant, // vscode.SymbolKind.Constant,
symbolRange, // symbolRange,
symbolRange); // symbolRange);
paramContainer.docSymbol?.children.push(paramDocSymbol); // paramContainer.docSymbol?.children.push(paramDocSymbol);
} else if (portTypes.includes(symbol.type)) { // } else if (portTypes.includes(symbol.type)) {
if (!portContainer.range) { // if (!portContainer.range) {
portContainer.range = symbolRange; // portContainer.range = symbolRange;
portContainer.docSymbol = new vscode.DocumentSymbol('port', // portContainer.docSymbol = new vscode.DocumentSymbol('port',
'port description', // 'port description',
vscode.SymbolKind.Method, // vscode.SymbolKind.Method,
symbolRange, // symbolRange,
symbolRange); // symbolRange);
moduleDocSymbol.children.push(portContainer.docSymbol); // moduleDocSymbol.children.push(portContainer.docSymbol);
} // }
const portDocSymbol = new vscode.DocumentSymbol(symbol.name, // const portDocSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.type, // symbol.type,
vscode.SymbolKind.Interface, // vscode.SymbolKind.Interface,
symbolRange, // symbolRange,
symbolRange); // symbolRange);
portContainer.docSymbol?.children.push(portDocSymbol); // portContainer.docSymbol?.children.push(portDocSymbol);
} else { // } else {
const symbolKind = this.getSymbolKind(symbol.type); // const symbolKind = this.getSymbolKind(symbol.type);
const symbolDocSymbol = new vscode.DocumentSymbol(symbol.name, // const symbolDocSymbol = new vscode.DocumentSymbol(symbol.name,
symbol.type, // symbol.type,
symbolKind, // symbolKind,
symbolRange, // symbolRange,
symbolRange); // symbolRange);
moduleDocSymbol.children.push(symbolDocSymbol); // moduleDocSymbol.children.push(symbolDocSymbol);
} // }
} // }
} // }
return docSymbols; // return docSymbols;
} // }
private getSymbolKind(name: string): vscode.SymbolKind { // private getSymbolKind(name: string): vscode.SymbolKind {
if (name.indexOf('[') !== -1) { // if (name.indexOf('[') !== -1) {
return vscode.SymbolKind.Array; // return vscode.SymbolKind.Array;
} // }
switch (name) { // switch (name) {
case 'module': return vscode.SymbolKind.Class; // case 'module': return vscode.SymbolKind.Class;
case 'program': return vscode.SymbolKind.Module; // case 'program': return vscode.SymbolKind.Module;
case 'package': return vscode.SymbolKind.Package; // case 'package': return vscode.SymbolKind.Package;
case 'import': return vscode.SymbolKind.Package; // case 'import': return vscode.SymbolKind.Package;
case 'always': return vscode.SymbolKind.Operator; // case 'always': return vscode.SymbolKind.Operator;
case 'processe': return vscode.SymbolKind.Operator; // case 'processe': return vscode.SymbolKind.Operator;
case 'task': return vscode.SymbolKind.Method; // case 'task': return vscode.SymbolKind.Method;
case 'function': return vscode.SymbolKind.Function; // case 'function': return vscode.SymbolKind.Function;
case 'assert': return vscode.SymbolKind.Boolean; // case 'assert': return vscode.SymbolKind.Boolean;
case 'event': return vscode.SymbolKind.Event; // case 'event': return vscode.SymbolKind.Event;
case 'instance': return vscode.SymbolKind.Event; // case 'instance': return vscode.SymbolKind.Event;
case 'time': return vscode.SymbolKind.TypeParameter; // case 'time': return vscode.SymbolKind.TypeParameter;
case 'define': return vscode.SymbolKind.TypeParameter; // case 'define': return vscode.SymbolKind.TypeParameter;
case 'typedef': return vscode.SymbolKind.TypeParameter; // case 'typedef': return vscode.SymbolKind.TypeParameter;
case 'generate': return vscode.SymbolKind.Operator; // case 'generate': return vscode.SymbolKind.Operator;
case 'enum': return vscode.SymbolKind.Enum; // case 'enum': return vscode.SymbolKind.Enum;
case 'modport': return vscode.SymbolKind.Boolean; // case 'modport': return vscode.SymbolKind.Boolean;
case 'property': return vscode.SymbolKind.Property; // case 'property': return vscode.SymbolKind.Property;
// port // // port
case 'interface': return vscode.SymbolKind.Interface; // case 'interface': return vscode.SymbolKind.Interface;
case 'buffer': return vscode.SymbolKind.Interface; // case 'buffer': return vscode.SymbolKind.Interface;
case 'output': return vscode.SymbolKind.Interface; // case 'output': return vscode.SymbolKind.Interface;
case 'input': return vscode.SymbolKind.Interface; // case 'input': return vscode.SymbolKind.Interface;
case 'inout': return vscode.SymbolKind.Interface; // case 'inout': return vscode.SymbolKind.Interface;
// synth param // // synth param
case 'localparam': return vscode.SymbolKind.Constant; // case 'localparam': return vscode.SymbolKind.Constant;
case 'parameter': return vscode.SymbolKind.Constant; // case 'parameter': return vscode.SymbolKind.Constant;
case 'integer': return vscode.SymbolKind.Number; // case 'integer': return vscode.SymbolKind.Number;
case 'char': return vscode.SymbolKind.Number; // case 'char': return vscode.SymbolKind.Number;
case 'float': return vscode.SymbolKind.Number; // case 'float': return vscode.SymbolKind.Number;
case 'int': return vscode.SymbolKind.Number; // case 'int': return vscode.SymbolKind.Number;
// unsynth param // // unsynth param
case 'string': return vscode.SymbolKind.String; // case 'string': return vscode.SymbolKind.String;
case 'struct': return vscode.SymbolKind.Struct; // case 'struct': return vscode.SymbolKind.Struct;
case 'class': return vscode.SymbolKind.Class; // case 'class': return vscode.SymbolKind.Class;
case 'logic': return vscode.SymbolKind.Constant; // case 'logic': return vscode.SymbolKind.Constant;
case 'wire': return vscode.SymbolKind.Constant; // case 'wire': return vscode.SymbolKind.Constant;
case 'reg': return vscode.SymbolKind.Constant; // case 'reg': return vscode.SymbolKind.Constant;
case 'net': return vscode.SymbolKind.Variable; // case 'net': return vscode.SymbolKind.Variable;
case 'bit': return vscode.SymbolKind.Boolean; // case 'bit': return vscode.SymbolKind.Boolean;
default: return vscode.SymbolKind.Event; // default: return vscode.SymbolKind.Event;
} // }
} // }
} // }
const vlogDocSymbolProvider = new VlogDocSymbolProvider(); // const vlogDocSymbolProvider = new VlogDocSymbolProvider();
export { // export {
vlogDocSymbolProvider // vlogDocSymbolProvider
}; // };

View File

@ -1,7 +1,7 @@
import { vlogHoverProvider } from './vlog'; // import { vlogHoverProvider } from './vlog';
import { vhdlHoverProvider } from './vhdl'; // import { vhdlHoverProvider } from './vhdl';
export { // export {
vlogHoverProvider, // vlogHoverProvider,
vhdlHoverProvider // vhdlHoverProvider
}; // };

View File

@ -2,181 +2,179 @@ import * as vscode from 'vscode';
import { hdlPath } from '../../../hdlFs'; import { hdlPath } from '../../../hdlFs';
import { hdlParam } from '../../../hdlParser'; import { hdlParam } from '../../../hdlParser';
import { All } from '../../../../resources/hdlParser';
import { vhdlKeyword } from '../util/keyword'; import { vhdlKeyword } from '../util/keyword';
import * as util from '../util'; import * as util from '../util';
import { MainOutput, ReportType } from '../../../global'; import { MainOutput, ReportType } from '../../../global';
import { HdlLangID } from '../../../global/enum'; import { HdlLangID } from '../../../global/enum';
import { hdlSymbolStorage } from '../core';
import { RawSymbol } from '../../../hdlParser/common'; import { RawSymbol } from '../../../hdlParser/common';
class VhdlHoverProvider implements vscode.HoverProvider { // class VhdlHoverProvider implements vscode.HoverProvider {
public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | null> { // public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | null> {
// console.log('VhdlHoverProvider'); // // console.log('VhdlHoverProvider');
// get current words // // get current words
const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/); // const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/);
if (!wordRange) { // if (!wordRange) {
return null; // return null;
} // }
const targetWord = document.getText(wordRange); // const targetWord = document.getText(wordRange);
// check if need skip // // check if need skip
if (this.needSkip(document, position, targetWord)) { // if (this.needSkip(document, position, targetWord)) {
return null; // return null;
} // }
const keywordHover = this.getKeywordHover(targetWord); // const keywordHover = this.getKeywordHover(targetWord);
if (keywordHover) { // if (keywordHover) {
return keywordHover; // return keywordHover;
} // }
const filePath = document.fileName; // const filePath = document.fileName;
const vhdlAll = await hdlSymbolStorage.getSymbol(filePath); // const vhdlAll = await hdlSymbolStorage.getSymbol(filePath);
if (!vhdlAll) { // if (!vhdlAll) {
return null; // return null;
} else { // } else {
const hover = await this.makeHover(document, position, vhdlAll, targetWord, wordRange); // const hover = await this.makeHover(document, position, vhdlAll, targetWord, wordRange);
return hover; // return hover;
} // }
} // }
private getKeywordHover(words: string): vscode.Hover | undefined { // private getKeywordHover(words: string): vscode.Hover | undefined {
const content = new vscode.MarkdownString('', true); // const content = new vscode.MarkdownString('', true);
if (vhdlKeyword.compilerKeys().has(words)) { // if (vhdlKeyword.compilerKeys().has(words)) {
content.appendMarkdown('IEEE Library data type'); // content.appendMarkdown('IEEE Library data type');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
return undefined; // return undefined;
} // }
private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean { // private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean {
// check keyword // // check keyword
if (vhdlKeyword.isKeyword(targetWord)) { // if (vhdlKeyword.isKeyword(targetWord)) {
return true; // return true;
} // }
// TODO: check comment // // TODO: check comment
return false; // return false;
} // }
private async makeHover(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Hover | null> { // private async makeHover(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Hover | null> {
const lineText = document.lineAt(position).text; // const lineText = document.lineAt(position).text;
const filePath = hdlPath.toSlash(document.fileName); // const filePath = hdlPath.toSlash(document.fileName);
// locate at one entity or architecture // // locate at one entity or architecture
// TODO: remove it after adjust of backend // // TODO: remove it after adjust of backend
const rawSymbols = []; // const rawSymbols = [];
for (const symbol of all.content) { // for (const symbol of all.content) {
const rawSymbol: RawSymbol = { // const rawSymbol: RawSymbol = {
name: symbol.name, // name: symbol.name,
type: symbol.type, // type: symbol.type,
parent: symbol.parent, // parent: symbol.parent,
range: util.transformRange(symbol.range, -1), // range: util.transformRange(symbol.range, -1),
signed: symbol.signed, // signed: symbol.signed,
netType: symbol.netType // netType: symbol.netType
}; // };
rawSymbols.push(rawSymbol); // rawSymbols.push(rawSymbol);
} // }
const moduleScope = util.locateVhdlSymbol(position, rawSymbols); // const moduleScope = util.locateVhdlSymbol(position, rawSymbols);
if (!moduleScope) { // if (!moduleScope) {
return null; // return null;
} // }
const scopeType = moduleScope.module.type; // const scopeType = moduleScope.module.type;
if (scopeType === 'architecture') { // if (scopeType === 'architecture') {
return await this.makeArchitectureHover(filePath, targetWord, targetWordRange, moduleScope); // return await this.makeArchitectureHover(filePath, targetWord, targetWordRange, moduleScope);
} else if (scopeType === 'entity') { // } else if (scopeType === 'entity') {
return await this.makeEntityHover(filePath, targetWord, targetWordRange, moduleScope); // return await this.makeEntityHover(filePath, targetWord, targetWordRange, moduleScope);
} // }
return null; // return null;
} // }
private async makeArchitectureHover(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Hover | null> { // private async makeArchitectureHover(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Hover | null> {
const architecture = moduleScope.module; // const architecture = moduleScope.module;
const content = new vscode.MarkdownString('', true); // const content = new vscode.MarkdownString('', true);
// point to the entity of the architecture // // point to the entity of the architecture
if (architecture.parent && architecture.parent === targetWord) { // if (architecture.parent && architecture.parent === targetWord) {
const entity = hdlParam.getHdlModule(filePath, architecture.parent); // const entity = hdlParam.getHdlModule(filePath, architecture.parent);
if (entity) { // if (entity) {
await util.makeVhdlHoverContent(content, entity); // await util.makeVhdlHoverContent(content, entity);
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
// filter defined signal // // filter defined signal
for (const symbol of moduleScope.symbols) { // for (const symbol of moduleScope.symbols) {
if (symbol.name === targetWord) { // if (symbol.name === targetWord) {
content.appendCodeblock(symbol.type, 'vhdl'); // content.appendCodeblock(symbol.type, 'vhdl');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
// inner variable mapping to entity // // inner variable mapping to entity
if (architecture.parent) { // if (architecture.parent) {
const entity = hdlParam.getHdlModule(filePath, architecture.parent); // const entity = hdlParam.getHdlModule(filePath, architecture.parent);
if (entity) { // if (entity) {
// find params definitio // // find params definitio
for (const param of entity.params) { // for (const param of entity.params) {
if (param.name === targetWord) { // if (param.name === targetWord) {
const desc = util.makeParamDesc(param); // const desc = util.makeParamDesc(param);
content.appendCodeblock(desc, 'vhdl'); // content.appendCodeblock(desc, 'vhdl');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
// find ports definition // // find ports definition
for (const port of entity.ports) { // for (const port of entity.ports) {
if (port.name === targetWord) { // if (port.name === targetWord) {
const desc = util.makePortDesc(port); // const desc = util.makePortDesc(port);
content.appendCodeblock(desc, 'vhdl'); // content.appendCodeblock(desc, 'vhdl');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
} // }
} // }
return null; // return null;
} // }
private async makeEntityHover(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Hover | null> { // private async makeEntityHover(filePath: string, targetWord: string, targetWordRange: vscode.Range, moduleScope: util.ModuleScope): Promise<vscode.Hover | null> {
const entity = hdlParam.getHdlModule(filePath, moduleScope.module.name); // const entity = hdlParam.getHdlModule(filePath, moduleScope.module.name);
const content = new vscode.MarkdownString('', true); // const content = new vscode.MarkdownString('', true);
if (entity) { // if (entity) {
if (targetWord === entity.name) { // if (targetWord === entity.name) {
await util.makeVhdlHoverContent(content, entity); // await util.makeVhdlHoverContent(content, entity);
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
// find params definitio // // find params definitio
for (const param of entity.params) { // for (const param of entity.params) {
if (param.name === targetWord) { // if (param.name === targetWord) {
const desc = util.makeParamDesc(param); // const desc = util.makeParamDesc(param);
content.appendCodeblock(desc, 'vhdl'); // content.appendCodeblock(desc, 'vhdl');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
// find ports definition // // find ports definition
for (const port of entity.ports) { // for (const port of entity.ports) {
if (port.name === targetWord) { // if (port.name === targetWord) {
const desc = util.makePortDesc(port); // const desc = util.makePortDesc(port);
content.appendCodeblock(desc, 'vhdl'); // content.appendCodeblock(desc, 'vhdl');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
} // }
return null; // return null;
} // }
} // }
const vhdlHoverProvider = new VhdlHoverProvider(); // const vhdlHoverProvider = new VhdlHoverProvider();
export { // export {
vhdlHoverProvider // vhdlHoverProvider
}; // };

View File

@ -2,210 +2,208 @@ import * as vscode from 'vscode';
import { hdlPath } from '../../../hdlFs'; import { hdlPath } from '../../../hdlFs';
import { hdlParam } from '../../../hdlParser'; import { hdlParam } from '../../../hdlParser';
import { All } from '../../../../resources/hdlParser';
import { vlogKeyword } from '../util/keyword'; import { vlogKeyword } from '../util/keyword';
import * as util from '../util'; import * as util from '../util';
import { LspOutput, MainOutput, ReportType } from '../../../global'; import { LspOutput, MainOutput, ReportType } from '../../../global';
import { HdlLangID } from '../../../global/enum'; import { HdlLangID } from '../../../global/enum';
import { hdlSymbolStorage } from '../core';
class VlogHoverProvider implements vscode.HoverProvider { // class VlogHoverProvider implements vscode.HoverProvider {
public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | null> { // public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Hover | null> {
// console.log('VlogHoverProvider'); // // console.log('VlogHoverProvider');
// get current words // // get current words
const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/); // const wordRange = document.getWordRangeAtPosition(position, /[`_0-9A-Za-z]+/);
if (!wordRange) { // if (!wordRange) {
return null; // return null;
} // }
const targetWord = document.getText(wordRange); // const targetWord = document.getText(wordRange);
// check if need skip // // check if need skip
if (this.needSkip(document, position, targetWord)) { // if (this.needSkip(document, position, targetWord)) {
return null; // return null;
} // }
const filePath = document.fileName; // const filePath = document.fileName;
const vlogAll = await hdlSymbolStorage.getSymbol(filePath); // const vlogAll = await hdlSymbolStorage.getSymbol(filePath);
if (!vlogAll) { // if (!vlogAll) {
return null; // return null;
} else { // } else {
const hover = await this.makeHover(document, position, vlogAll, targetWord, wordRange); // const hover = await this.makeHover(document, position, vlogAll, targetWord, wordRange);
return hover; // return hover;
} // }
} // }
private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean { // private needSkip(document: vscode.TextDocument, position: vscode.Position, targetWord: string): boolean {
// check keyword // // check keyword
if (vlogKeyword.isKeyword(targetWord)) { // if (vlogKeyword.isKeyword(targetWord)) {
return true; // return true;
} // }
// TODO: check comment // // TODO: check comment
return false; // return false;
} // }
private async makeHover(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Hover | null> { // private async makeHover(document: vscode.TextDocument, position: vscode.Position, all: All, targetWord: string, targetWordRange: vscode.Range): Promise<vscode.Hover | null> {
const lineText = document.lineAt(position).text; // const lineText = document.lineAt(position).text;
const filePath = hdlPath.toSlash(document.fileName); // const filePath = hdlPath.toSlash(document.fileName);
// total content rendered on the hover box // // total content rendered on the hover box
const content = new vscode.MarkdownString('', true); // const content = new vscode.MarkdownString('', true);
// match `include // // match `include
const includeResult = util.matchInclude(document, position, all.macro.includes); // const includeResult = util.matchInclude(document, position, all.macro.includes);
if (includeResult) { // if (includeResult) {
const absPath = hdlPath.rel2abs(filePath, includeResult.name); // const absPath = hdlPath.rel2abs(filePath, includeResult.name);
content.appendCodeblock(`"${absPath}"`, HdlLangID.Verilog); // content.appendCodeblock(`"${absPath}"`, HdlLangID.Verilog);
const targetRange = document.getWordRangeAtPosition(position, /[1-9a-zA-Z_\.]+/); // const targetRange = document.getWordRangeAtPosition(position, /[1-9a-zA-Z_\.]+/);
return new vscode.Hover(content, targetRange); // return new vscode.Hover(content, targetRange);
} else if (lineText.trim().startsWith('`include')) { // } else if (lineText.trim().startsWith('`include')) {
return null; // return null;
} // }
// match macro // // match macro
const macroResult = util.matchDefineMacro(position, targetWord, all.macro.defines); // const macroResult = util.matchDefineMacro(position, targetWord, all.macro.defines);
if (macroResult) { // if (macroResult) {
const name = macroResult.name; // const name = macroResult.name;
const value = macroResult.value; // const value = macroResult.value;
content.appendCodeblock(`\`define ${name} ${value}`, HdlLangID.Verilog); // content.appendCodeblock(`\`define ${name} ${value}`, HdlLangID.Verilog);
return new vscode.Hover(content, targetWordRange); // return new vscode.Hover(content, targetWordRange);
} // }
// locate at one module // // locate at one module
const scopeSymbols = util.locateVlogSymbol(position, all.content); // const scopeSymbols = util.locateVlogSymbol(position, all.content);
if (!scopeSymbols || !scopeSymbols.module || !hdlParam.hasHdlModule(filePath, scopeSymbols.module.name)) { // if (!scopeSymbols || !scopeSymbols.module || !hdlParam.hasHdlModule(filePath, scopeSymbols.module.name)) {
return null; // return null;
} // }
const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name); // const currentModule = hdlParam.getHdlModule(filePath, scopeSymbols.module.name);
if (!currentModule) { // if (!currentModule) {
MainOutput.report('Fail to get HdlModule ' + filePath + ' ' + scopeSymbols.module.name, ReportType.Debug); // MainOutput.report('Fail to get HdlModule ' + filePath + ' ' + scopeSymbols.module.name, ReportType.Debug);
return null; // return null;
} // }
// match instance // // match instance
const instResult = util.matchInstance(targetWord, currentModule); // const instResult = util.matchInstance(targetWord, currentModule);
if (instResult) { // if (instResult) {
const instModule = instResult.module; // const instModule = instResult.module;
if (!instModule || !instResult.instModPath) { // if (!instModule || !instResult.instModPath) {
content.appendMarkdown('cannot find the definition of the module'); // content.appendMarkdown('cannot find the definition of the module');
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
await util.makeVlogHoverContent(content, instModule); // await util.makeVlogHoverContent(content, instModule);
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
// match port or param definition (position input) // // match port or param definition (position input)
/** for example, when you hover the ".clk" below, the branch will be entered // /** for example, when you hover the ".clk" below, the branch will be entered
template u_template( // template u_template(
//input // //input
.clk ( clk ), // .clk ( clk ),
); // );
* // *
*/ // */
if (util.isPositionInput(lineText, position.character)) { // if (util.isPositionInput(lineText, position.character)) {
// console.log('enter position input'); // // console.log('enter position input');
const currentInstResult = util.filterInstanceByPosition(position, scopeSymbols.symbols, currentModule); // const currentInstResult = util.filterInstanceByPosition(position, scopeSymbols.symbols, currentModule);
if (!currentInstResult || !currentInstResult.instModPath) { // if (!currentInstResult || !currentInstResult.instModPath) {
return null; // return null;
} // }
// console.log(currentInstResult); // // console.log(currentInstResult);
const instParamPromise = util.getInstParamByPosition(currentInstResult, position, targetWord); // const instParamPromise = util.getInstParamByPosition(currentInstResult, position, targetWord);
const instPortPromise = util.getInstPortByPosition(currentInstResult, position, targetWord); // const instPortPromise = util.getInstPortByPosition(currentInstResult, position, targetWord);
const instParam = await instParamPromise; // const instParam = await instParamPromise;
const instPort = await instPortPromise; // const instPort = await instPortPromise;
if (instParam) { // if (instParam) {
const paramComment = await util.searchCommentAround(currentInstResult.instModPath, instParam.range); // const paramComment = await util.searchCommentAround(currentInstResult.instModPath, instParam.range);
const paramDesc = util.makeParamDesc(instParam); // const paramDesc = util.makeParamDesc(instParam);
content.appendCodeblock(paramDesc, HdlLangID.Verilog); // content.appendCodeblock(paramDesc, HdlLangID.Verilog);
if (paramComment) { // if (paramComment) {
content.appendCodeblock(paramComment, HdlLangID.Verilog); // content.appendCodeblock(paramComment, HdlLangID.Verilog);
} // }
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
if (instPort) { // if (instPort) {
const portComment = await util.searchCommentAround(currentInstResult.instModPath, instPort.range); // const portComment = await util.searchCommentAround(currentInstResult.instModPath, instPort.range);
const portDesc = util.makePortDesc(instPort); // const portDesc = util.makePortDesc(instPort);
content.appendCodeblock(portDesc, HdlLangID.Verilog); // content.appendCodeblock(portDesc, HdlLangID.Verilog);
if (portComment) { // if (portComment) {
content.appendCodeblock(portComment, HdlLangID.Verilog); // content.appendCodeblock(portComment, HdlLangID.Verilog);
} // }
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
return null; // return null;
} // }
// match params // // match params
const paramResult = util.matchParams(targetWord, currentModule); // const paramResult = util.matchParams(targetWord, currentModule);
if (paramResult) { // if (paramResult) {
LspOutput.report('<vlog hover> get param info ' + paramResult?.name, ReportType.Info); // LspOutput.report('<vlog hover> get param info ' + paramResult?.name, ReportType.Info);
const paramComment = await util.searchCommentAround(filePath, paramResult.range); // const paramComment = await util.searchCommentAround(filePath, paramResult.range);
const paramDesc = util.makeParamDesc(paramResult); // const paramDesc = util.makeParamDesc(paramResult);
content.appendCodeblock(paramDesc, HdlLangID.Verilog); // content.appendCodeblock(paramDesc, HdlLangID.Verilog);
if (paramComment) { // if (paramComment) {
content.appendMarkdown(paramComment); // content.appendMarkdown(paramComment);
} // }
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
// match ports // // match ports
const portResult = util.matchPorts(targetWord, currentModule); // const portResult = util.matchPorts(targetWord, currentModule);
if (portResult) { // if (portResult) {
LspOutput.report('<vlog hover> get port info ' + portResult?.name, ReportType.Info); // LspOutput.report('<vlog hover> get port info ' + portResult?.name, ReportType.Info);
const portComment = await util.searchCommentAround(filePath, portResult.range); // const portComment = await util.searchCommentAround(filePath, portResult.range);
const portDesc = util.makePortDesc(portResult); // const portDesc = util.makePortDesc(portResult);
content.appendCodeblock(portDesc, HdlLangID.Verilog); // content.appendCodeblock(portDesc, HdlLangID.Verilog);
if (portComment) { // if (portComment) {
content.appendMarkdown(portComment); // content.appendMarkdown(portComment);
} // }
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
// match others // // match others
const normalResult = util.matchNormalSymbol(targetWord, scopeSymbols.symbols); // const normalResult = util.matchNormalSymbol(targetWord, scopeSymbols.symbols);
if (normalResult) { // if (normalResult) {
const normalComment = await util.searchCommentAround(filePath, normalResult.range); // const normalComment = await util.searchCommentAround(filePath, normalResult.range);
const normalDesc = util.makeNormalDesc(normalResult); // const normalDesc = util.makeNormalDesc(normalResult);
content.appendCodeblock(normalDesc, HdlLangID.Verilog); // content.appendCodeblock(normalDesc, HdlLangID.Verilog);
if (normalComment) { // if (normalComment) {
content.appendCodeblock(normalComment, HdlLangID.Verilog); // content.appendCodeblock(normalComment, HdlLangID.Verilog);
} // }
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
// feature 1. number signed and unsigned number display // // feature 1. number signed and unsigned number display
const numberResult = util.transferVlogNumber(lineText, position.character); // const numberResult = util.transferVlogNumber(lineText, position.character);
if (numberResult) { // if (numberResult) {
const bits = targetWord.length - 1; // const bits = targetWord.length - 1;
content.appendCodeblock(bits + "'" + targetWord, HdlLangID.Verilog); // content.appendCodeblock(bits + "'" + targetWord, HdlLangID.Verilog);
content.appendMarkdown("`unsigned` " + numberResult.unsigned); // content.appendMarkdown("`unsigned` " + numberResult.unsigned);
content.appendText('\n'); // content.appendText('\n');
content.appendMarkdown("`signed` " + numberResult.signed); // content.appendMarkdown("`signed` " + numberResult.signed);
} // }
return new vscode.Hover(content); // return new vscode.Hover(content);
} // }
} // }
const vlogHoverProvider = new VlogHoverProvider(); // const vlogHoverProvider = new VlogHoverProvider();
export { // export {
vlogHoverProvider // vlogHoverProvider
}; // };

View File

@ -1,6 +1,6 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { isVerilogFile, isVhdlFile } from '../../../hdlFs/file'; import { isVerilogFile, isVhdlFile } from '../../../hdlFs/file';
import { Position } from '../../../hdlParser/common'; import { All, Position } from '../../../hdlParser/common';
import { BaseLinter } from './base'; import { BaseLinter } from './base';
import { LspOutput, ReportType } from '../../../global'; import { LspOutput, ReportType } from '../../../global';

View File

@ -2,7 +2,6 @@ import * as vscode from "vscode";
import * as fs from 'fs'; import * as fs from 'fs';
import { LspOutput, ReportType, opeParam } from "../../../global"; import { LspOutput, ReportType, opeParam } from "../../../global";
import { Path } from "../../../../resources/hdlParser";
import { hdlFile, hdlPath } from "../../../hdlFs"; import { hdlFile, hdlPath } from "../../../hdlFs";
import { easyExec } from "../../../global/util"; import { easyExec } from "../../../global/util";
import { BaseLinter } from "./base"; import { BaseLinter } from "./base";
@ -125,7 +124,7 @@ class ModelsimLinter implements BaseLinter {
} }
} }
public getExecutableFilePath(langID: HdlLangID): string | Path | undefined { public getExecutableFilePath(langID: HdlLangID): string | undefined {
// modelsim install path stored in prj.modelsim.install.path // modelsim install path stored in prj.modelsim.install.path
const modelsimConfig = vscode.workspace.getConfiguration('digital-ide.prj.modelsim'); const modelsimConfig = vscode.workspace.getConfiguration('digital-ide.prj.modelsim');
const modelsimInstallPath = modelsimConfig.get('install.path', ''); const modelsimInstallPath = modelsimConfig.get('install.path', '');
@ -156,7 +155,7 @@ class ModelsimLinter implements BaseLinter {
} }
public async setExecutableFilePath(executorPath: string | Path | undefined, langID: HdlLangID): Promise<boolean> { public async setExecutableFilePath(executorPath: string | undefined, langID: HdlLangID): Promise<boolean> {
if (executorPath === undefined) { if (executorPath === undefined) {
return false; return false;
} }

View File

@ -2,12 +2,13 @@ import * as vscode from "vscode";
import * as fs from 'fs'; import * as fs from 'fs';
import { LspOutput, ReportType, opeParam } from "../../../global"; import { LspOutput, ReportType, opeParam } from "../../../global";
import { Path } from "../../../../resources/hdlParser";
import { hdlFile, hdlPath } from "../../../hdlFs"; import { hdlFile, hdlPath } from "../../../hdlFs";
import { easyExec } from "../../../global/util"; import { easyExec } from "../../../global/util";
import { BaseLinter } from "./base"; import { BaseLinter } from "./base";
import { HdlLangID } from "../../../global/enum"; import { HdlLangID } from "../../../global/enum";
type Path = string;
class VerilatorLinter implements BaseLinter { class VerilatorLinter implements BaseLinter {
diagnostic: vscode.DiagnosticCollection; diagnostic: vscode.DiagnosticCollection;
executableFileMap: Map<HdlLangID, string | undefined> = new Map<HdlLangID, string>(); executableFileMap: Map<HdlLangID, string | undefined> = new Map<HdlLangID, string>();

View File

@ -2,12 +2,13 @@ import * as vscode from "vscode";
import * as fs from 'fs'; import * as fs from 'fs';
import { LspOutput, ReportType, opeParam } from "../../../global"; import { LspOutput, ReportType, opeParam } from "../../../global";
import { Path } from "../../../../resources/hdlParser";
import { hdlFile, hdlPath } from "../../../hdlFs"; import { hdlFile, hdlPath } from "../../../hdlFs";
import { easyExec } from "../../../global/util"; import { easyExec } from "../../../global/util";
import { BaseLinter } from "./base"; import { BaseLinter } from "./base";
import { HdlLangID } from "../../../global/enum"; import { HdlLangID } from "../../../global/enum";
type Path = string;
class VivadoLinter implements BaseLinter { class VivadoLinter implements BaseLinter {
diagnostic: vscode.DiagnosticCollection; diagnostic: vscode.DiagnosticCollection;
executableFileMap: Map<HdlLangID, string | undefined> = new Map<HdlLangID, string>(); executableFileMap: Map<HdlLangID, string | undefined> = new Map<HdlLangID, string>();

View File

@ -8,9 +8,10 @@ import { hdlDir, hdlFile, hdlPath } from '../../hdlFs';
import { getSelectItem } from './instance'; import { getSelectItem } from './instance';
import { ToolChainType } from '../../global/enum'; import { ToolChainType } from '../../global/enum';
import { HdlModule } from '../../hdlParser/core'; import { HdlModule } from '../../hdlParser/core';
import { Path } from '../../../resources/hdlParser';
import { ModuleDataItem } from '../treeView/tree'; import { ModuleDataItem } from '../treeView/tree';
type Path = string;
interface SimulateConfig { interface SimulateConfig {
mod : string, // 设置的顶层模块 mod : string, // 设置的顶层模块
clk : string, // 设置的主频信号 clk : string, // 设置的主频信号

View File

@ -5,13 +5,14 @@ import * as fspath from 'path';
import { AbsPath, opeParam } from '../global'; import { AbsPath, opeParam } from '../global';
import { hdlDir, hdlFile, hdlPath } from '../hdlFs'; import { hdlDir, hdlFile, hdlPath } from '../hdlFs';
import { Library } from '../global/prjInfo'; import { Library } from '../global/prjInfo';
import { Path } from '../../resources/hdlParser';
import { LibraryState } from '../global/enum'; import { LibraryState } from '../global/enum';
import { PathSet } from '../global/util'; import { PathSet } from '../global/util';
import { hdlIgnore } from './ignore'; import { hdlIgnore } from './ignore';
import { hdlParam } from '../hdlParser'; import { hdlParam } from '../hdlParser';
import { refreshArchTree } from '../function/treeView'; import { refreshArchTree } from '../function/treeView';
type Path = string;
interface LibFileChange { interface LibFileChange {
add: AbsPath[], add: AbsPath[],
del: AbsPath[], del: AbsPath[],

View File

@ -15,7 +15,7 @@ import { ppyAction } from '../monitor/event';
import { hdlMonitor } from '../monitor'; import { hdlMonitor } from '../monitor';
import { NotificationType } from 'vscode-jsonrpc'; import { NotificationType } from 'vscode-jsonrpc';
import { refreshArchTree } from '../function/treeView'; import { refreshArchTree } from '../function/treeView';
import { Fast } from '../../resources/hdlParser'; import { Fast } from '../hdlParser/common';
interface RefreshPrjConfig { interface RefreshPrjConfig {
mkdir: boolean mkdir: boolean