From 9f448850605d7a4ed72b117e92eff94874d2ddc1 Mon Sep 17 00:00:00 2001 From: LSTM-Kirigaya <1193466151@qq.com> Date: Wed, 8 Jan 2025 15:18:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20common=20=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E7=9A=84=20linter=20=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extension.ts | 5 ++++- src/function/dide-netlist/worker.ts | 6 ------ src/function/lsp-client/config.ts | 23 ++++++++++++++++++----- src/global/index.ts | 13 +++++++++++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 213e9f6..7f807e1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; import * as fs from 'fs'; -import { MainOutput, ReportType, IProgress } from './global'; +import { MainOutput, ReportType, IProgress, globalLookup } from './global'; import { hdlParam } from './hdlParser'; import * as manager from './manager'; import * as lspLinter from './function/lsp/linter'; @@ -72,6 +72,9 @@ async function launch(context: vscode.ExtensionContext) { await registerCommand(context, packageJson); }); + // 注册全局变量 + globalLookup.activeEditor = vscode.window.activeTextEditor; + await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: t('info.progress.initialize-configure') diff --git a/src/function/dide-netlist/worker.ts b/src/function/dide-netlist/worker.ts index 5c776c1..df79686 100644 --- a/src/function/dide-netlist/worker.ts +++ b/src/function/dide-netlist/worker.ts @@ -7,12 +7,6 @@ import { WASI } from 'wasi'; type SynthMode = 'before' | 'after' | 'RTL'; type AbsPath = string; -enum HdlLangID { - Verilog = 'verilog', - SystemVerilog = 'systemverilog', - Vhdl = 'vhdl', - Unknown = 'Unknown' -}; interface SimpleOpe { workspacePath: string, diff --git a/src/function/lsp-client/config.ts b/src/function/lsp-client/config.ts index 40f52b3..18df93c 100644 --- a/src/function/lsp-client/config.ts +++ b/src/function/lsp-client/config.ts @@ -5,9 +5,10 @@ import * as Linter from '../lsp/linter/common'; import { HdlLangID } from '../../global/enum'; import * as lspLinter from '../lsp/linter'; import { t } from '../../i18n'; -import { IProgress } from '../../global'; -import { refreshWorkspaceDiagonastics } from '../lsp/linter/manager'; +import { globalLookup, IProgress } from '../../global'; +import { clearDiagnostics, publishDiagnostics, refreshWorkspaceDiagonastics } from '../lsp/linter/manager'; import { prjManage } from '../../manager'; +import { hdlFile, hdlPath } from '../../hdlFs'; interface ConfigItem { name: string, @@ -167,12 +168,24 @@ export async function registerLinter(client: LanguageClient) { }); // 切换标签页时的行为 - vscode.window.onDidChangeActiveTextEditor(editor => { + vscode.window.onDidChangeActiveTextEditor(async editor => { if (!editor) { return; } - console.log('change to ', editor); - }) + const linterMode = Linter.getLinterMode(); + const currentPath = hdlPath.toEscapePath(editor.document.fileName); + if (globalLookup.activeEditor && linterMode === 'common') { + const previousPath = hdlPath.toEscapePath(globalLookup.activeEditor.document.fileName); + if (hdlFile.isHDLFile(previousPath)) { + clearDiagnostics(client, previousPath); + } + if (hdlFile.isHDLFile(currentPath)) { + publishDiagnostics(client, currentPath); + } + } + + globalLookup.activeEditor = editor; + }); } /** diff --git a/src/global/index.ts b/src/global/index.ts index 960e1d9..1c509c1 100644 --- a/src/global/index.ts +++ b/src/global/index.ts @@ -1,3 +1,4 @@ +import * as vscode from 'vscode'; import { opeParam, OpeParamDefaults } from './opeParam'; import { PrjInfo, PrjInfoDefaults } from './prjInfo'; import { MainOutput, LinterOutput, YosysOutput, WaveViewOutput, ReportType } from './outputChannel'; @@ -11,12 +12,19 @@ type RelPath = string; type AllowNull = T | null; - interface IProgress { message?: string, increment?: number } +interface IGlobalLookup { + activeEditor?: vscode.TextEditor +} + +const globalLookup: IGlobalLookup = { + activeEditor: undefined +}; + export { opeParam, OpeParamDefaults, @@ -33,5 +41,6 @@ export { ReportType, AllowNull, LspClient, - IProgress + IProgress, + globalLookup }; \ No newline at end of file