完成打包

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 { vhdlCompletionProvider } from './vhdl';
// import { vlogCompletionProvider, vlogIncludeCompletionProvider, vlogMacroCompletionProvider, vlogPositionPortProvider } from './vlog';
// import { vhdlCompletionProvider } from './vhdl';
import { tclCompletionProvider } from './tcl';
export {
vlogCompletionProvider,
vlogIncludeCompletionProvider,
vlogMacroCompletionProvider,
vlogPositionPortProvider,
vhdlCompletionProvider,
// vlogCompletionProvider,
// vlogIncludeCompletionProvider,
// vlogMacroCompletionProvider,
// vlogPositionPortProvider,
// vhdlCompletionProvider,
tclCompletionProvider
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@ import * as vscode from "vscode";
import * as fs from 'fs';
import { LspOutput, ReportType, opeParam } from "../../../global";
import { Path } from "../../../../resources/hdlParser";
import { hdlFile, hdlPath } from "../../../hdlFs";
import { easyExec } from "../../../global/util";
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
const modelsimConfig = vscode.workspace.getConfiguration('digital-ide.prj.modelsim');
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) {
return false;
}

View File

@ -2,12 +2,13 @@ import * as vscode from "vscode";
import * as fs from 'fs';
import { LspOutput, ReportType, opeParam } from "../../../global";
import { Path } from "../../../../resources/hdlParser";
import { hdlFile, hdlPath } from "../../../hdlFs";
import { easyExec } from "../../../global/util";
import { BaseLinter } from "./base";
import { HdlLangID } from "../../../global/enum";
type Path = string;
class VerilatorLinter implements BaseLinter {
diagnostic: vscode.DiagnosticCollection;
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 { LspOutput, ReportType, opeParam } from "../../../global";
import { Path } from "../../../../resources/hdlParser";
import { hdlFile, hdlPath } from "../../../hdlFs";
import { easyExec } from "../../../global/util";
import { BaseLinter } from "./base";
import { HdlLangID } from "../../../global/enum";
type Path = string;
class VivadoLinter implements BaseLinter {
diagnostic: vscode.DiagnosticCollection;
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 { ToolChainType } from '../../global/enum';
import { HdlModule } from '../../hdlParser/core';
import { Path } from '../../../resources/hdlParser';
import { ModuleDataItem } from '../treeView/tree';
type Path = string;
interface SimulateConfig {
mod : string, // 设置的顶层模块
clk : string, // 设置的主频信号

View File

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

View File

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