diff --git a/README.md b/README.md index 0af1fe0..9c7e599 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,8 @@ ![](https://img.shields.io/badge/version-0.3.0-blue) +```bash +npm i +``` + +Enter Vscode & F5 \ No newline at end of file diff --git a/package.json b/package.json index d68c917..66356e4 100644 --- a/package.json +++ b/package.json @@ -322,7 +322,7 @@ "activitybar": [ { "id": "TreeView", - "title": "Digital-IDE", + "title": "Digital-IDE: TreeView", "icon": "images/svg/view.svg" } ] diff --git a/project/property-init.json b/project/property-init.json index 07c77fc..5bff5f5 100644 --- a/project/property-init.json +++ b/project/property-init.json @@ -6,18 +6,6 @@ "soc": { "core": "none" }, - "arch": { - "prjPath": "./prj", - "hardware": { - "src": "./user/src", - "sim": "./user/sim", - "data": "./user/data" - }, - "software": { - "src": "./user/software/src", - "data": "./user/software/data" - } - }, "enableShowLog": false, "device": "none" } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 91b7703..bee71ba 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,7 @@ async function launch(context: vscode.ExtensionContext) { console.timeLog('launch'); - await registerCommand(context); + await registerCommand(context); MainOutput.report('Digital-IDE has launched, Version: 0.3.0'); MainOutput.report('OS: ' + opeParam.os); } diff --git a/src/function/treeView/index.ts b/src/function/treeView/index.ts index bd43c7b..42fbce7 100644 --- a/src/function/treeView/index.ts +++ b/src/function/treeView/index.ts @@ -3,11 +3,21 @@ import { hdlPath } from '../../hdlFs'; import { hardwareTreeProvider, softwareTreeProvider, toolTreeProvider } from './command'; import { moduleTreeProvider, ModuleDataItem } from './tree'; +import { Range } from '../../hdlParser/common'; +async function openFileAtPosition(uri: vscode.Uri, line: number, character: number) { + const document = await vscode.workspace.openTextDocument(uri); + const editor = await vscode.window.showTextDocument(document); + const position = new vscode.Position(line, character); + editor.selection = new vscode.Selection(position, position); + editor.revealRange(new vscode.Range(position, position)); +} -function openFileByUri(uri: string) { - if (hdlPath.exist(uri)) { - vscode.window.showTextDocument(vscode.Uri.file(uri)); +function openFileByUri(path: string, range: Range) { + if (hdlPath.exist(path)) { + const uri = vscode.Uri.file(path); + const start = range.start; + openFileAtPosition(uri, start.line - 1, start.character); } } diff --git a/src/function/treeView/tree.ts b/src/function/treeView/tree.ts index 15ef0fd..9f010d9 100644 --- a/src/function/treeView/tree.ts +++ b/src/function/treeView/tree.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { AbsPath, MainOutput, opeParam, ReportType } from '../../global'; import { SimPath, SrcPath } from '../../global/prjInfo'; import { HdlInstance, hdlParam } from '../../hdlParser/core'; -import { HdlFileType } from '../../hdlParser/common'; +import { HdlFileType, Range } from '../../hdlParser/common'; import { hdlFile, hdlPath } from '../../hdlFs'; import { xilinx, itemModes, otherModes } from './common'; import { getIconConfig } from '../../hdlFs/icons'; @@ -13,7 +13,8 @@ let needExpand = true; interface ModuleDataItem { icon: string, // 图标 name: string, // module name - type: string, + type: string, + range: Range | null, path: AbsPath | undefined, // path of the file parent: ModuleDataItem | null // parent file } @@ -64,8 +65,8 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { src: null, sim: null, }; - this.srcRootItem = {icon: 'src', type: HdlFileType.Src, name: 'src', path: '', parent: null}; - this.simRootItem = {icon: 'sim', type: HdlFileType.Sim, name: 'sim', path: '', parent: null}; + this.srcRootItem = {icon: 'src', type: HdlFileType.Src, name: 'src', range: null, path: '', parent: null}; + this.simRootItem = {icon: 'sim', type: HdlFileType.Sim, name: 'sim', range: null, path: '', parent: null}; } @@ -120,13 +121,12 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { // set iconPath treeItem.iconPath = getIconConfig(element.icon); - + // set command treeItem.command = { title: "Open this HDL File", - // TODO : 修改这里的指令前缀 - command: 'TOOL.tree.arch.openFile', - arguments: [element.path], + command: 'digital-ide.treeView.arch.openFile', + arguments: [element.path, element.range], }; return treeItem; @@ -164,6 +164,7 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { icon: 'top', type: moduleType, name: module.name, + range: module.range, path: module.path, parent: element, })); @@ -178,6 +179,7 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { const name = this.firstTop[type]!.name; const path = this.firstTop[type]!.path; const icon = this.makeFirstTopIconName(type); + const range = firstTop.range; const parent = element; const tops = topModuleItemList.filter(item => item.path === path && item.name === name); @@ -197,7 +199,7 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { } else { // mean the selected top is not an original top module // create it and add it to the head of *topModuleItemList* - const selectedTopItem: ModuleDataItem = {icon, type, name, path, parent}; + const selectedTopItem: ModuleDataItem = {icon, type, name, range, path, parent}; adjustItemList.push(selectedTopItem); adjustItemList.push(...topModuleItemList); } @@ -222,6 +224,7 @@ class ModuleTreeProvider implements vscode.TreeDataProvider { icon: 'file', type: instance.name, name: instance.type, + range: instance.module ? instance.module.range : null, path: instance.instModPath, parent: element }; diff --git a/src/global/prjInfo.ts b/src/global/prjInfo.ts index 1777476..2d05300 100644 --- a/src/global/prjInfo.ts +++ b/src/global/prjInfo.ts @@ -44,15 +44,15 @@ const PrjInfoDefaults: PrjInfoMeta = { device: 'none', arch: { - prjPath: '', + prjPath: './prj', hardware: { - src: '', - sim: '', - data: '' + src: './user/src', + sim: './user/sim', + data: './user/data' }, software: { - src: '', - data: '' + src: './user/software/src', + data: './user/software/data' } }, @@ -436,8 +436,13 @@ class PrjInfo implements PrjInfoMeta { } public getLibraryCustomPaths(absolute: boolean = true): Path[] { + const libCustomPath = this.libCustomPath; + if (libCustomPath === '') { + return []; + } + if (absolute) { - const configFolder = hdlPath.join(this.libCustomPath, 'Empty'); + const configFolder = hdlPath.join(libCustomPath, 'Empty'); return this._library.hardware.custom.map(relPath => hdlPath.rel2abs(configFolder, relPath)); } return this._library.hardware.custom; @@ -481,7 +486,7 @@ class PrjInfo implements PrjInfoMeta { public get libCustomPath(): AbsPath { const libPath = vscode.workspace.getConfiguration().get('prj.lib.custom.path', this._workspacePath); if (!fs.existsSync(libPath)) { - vscode.window.showErrorMessage('property "prj.lib.custom.path" is empty or is an invalid path'); + return ''; } return libPath; } diff --git a/src/manager/lib.ts b/src/manager/lib.ts index c21e851..ffbad5e 100644 --- a/src/manager/lib.ts +++ b/src/manager/lib.ts @@ -67,10 +67,6 @@ class LibManage { return hdlPath.join(opeParam.extensionPath, 'lib'); } - public get libCustomPath(): AbsPath { - return opeParam.prjInfo.libCustomPath; - } - public processLibFiles(library: Library): LibFileChange { // 在不设置state属性的时候默认为remote this.next.list = this.getLibFiles(library); diff --git a/src/manager/libPick.ts b/src/manager/libPick.ts index 8a15caf..046055e 100644 --- a/src/manager/libPick.ts +++ b/src/manager/libPick.ts @@ -155,6 +155,8 @@ class LibPick { if (selectedPath && hdlPath.exist(selectedPath)) { const userPrjInfo = opeParam.getUserPrjInfo(); + console.log(userPrjInfo); + if (selectedPath.includes(this.commonQuickPickItem.path!)) { // this is a module import from common, use relative path const relPath = selectedPath.replace(this.commonQuickPickItem.path + '/', ''); diff --git a/src/manager/prj.ts b/src/manager/prj.ts index 1ed9d45..34791ee 100644 --- a/src/manager/prj.ts +++ b/src/manager/prj.ts @@ -16,7 +16,7 @@ class PrjManage { return; } const template = hdlFile.readJSON(opeParam.propertyInitPath) as RawPrjInfo; - template.arch?.hardware. + hdlFile.writeJSON(opeParam.propertyJsonPath, template); }