From 9ab7c4c43993f67169141f6e6ffc7dfb1c9d1abb Mon Sep 17 00:00:00 2001 From: hongjr03 Date: Fri, 29 May 2026 14:17:46 +0800 Subject: [PATCH 1/4] fix: exclude declarations from references --- editors/vscode/src/extension.ts | 12 +++++ playground/src/lab/lsp-client.ts | 10 ++++ src/global_state/handlers/request.rs | 4 +- src/tests.rs | 71 +++++++++++++++++++++++++++- 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts index 08362f11..a98539eb 100644 --- a/editors/vscode/src/extension.ts +++ b/editors/vscode/src/extension.ts @@ -62,6 +62,14 @@ const activeQiheTokens = new Set(); const qiheProgressNotifications = new Map void }>(); let qiheStatusHideTimer: NodeJS.Timeout | undefined; +function referencesRequestOptions( + options: { includeDeclaration: boolean }, +): { includeDeclaration: boolean } { + // Vide surfaces references as actual usages; declarations stay available through + // go to definition / declaration instead of being mixed into the references list. + return options.includeDeclaration ? { ...options, includeDeclaration: false } : options; +} + function log(message: string): void { outputChannel?.appendLine(message); } @@ -649,6 +657,10 @@ async function createClient(context: vscode.ExtensionContext): Promise + next(document, position, referencesRequestOptions(options), token), + }, ...(config.trace !== 'off' && { trace: config.trace }), }; diff --git a/playground/src/lab/lsp-client.ts b/playground/src/lab/lsp-client.ts index 188a4511..3748abb0 100644 --- a/playground/src/lab/lsp-client.ts +++ b/playground/src/lab/lsp-client.ts @@ -14,6 +14,14 @@ import { BrowserMessageReader, BrowserMessageWriter } from "vscode-languageserve const CLIENT_DISPOSED_MESSAGE = "Vide LSP client has been disposed."; +function referencesRequestOptions( + options: { includeDeclaration: boolean }, +): { includeDeclaration: boolean } { + // Match the desktop extension: references should list usages only, while + // definitions remain reachable via definition / declaration navigation. + return options.includeDeclaration ? { ...options, includeDeclaration: false } : options; +} + export function isClientDisposedError(error: unknown): boolean { return error instanceof Error && error.message === CLIENT_DISPOSED_MESSAGE; } @@ -116,6 +124,8 @@ export class VideBrowserClient { handleDiagnostics: (uri, diagnostics, next) => { next(uri, diagnostics); }, + provideReferences: (document, position, options, token, next) => + next(document, position, referencesRequestOptions(options), token), workspace: { configuration: () => [], }, diff --git a/src/global_state/handlers/request.rs b/src/global_state/handlers/request.rs index a5e4dcef..a24c2ffe 100644 --- a/src/global_state/handlers/request.rs +++ b/src/global_state/handlers/request.rs @@ -347,6 +347,7 @@ pub(crate) fn handle_references( snap: GlobalStateSnapshot, params: lsp_types::ReferenceParams, ) -> anyhow::Result>> { + let include_declaration = params.context.include_declaration; let position = from_proto::file_position(&snap, params.text_document_position)?; let config = snap.config.references(); let Some(refs) = snap.analysis.references(position, config)? else { @@ -356,9 +357,8 @@ pub(crate) fn handle_references( let locations = refs .into_iter() .flat_map(|References { def, refs }| { - let decl = def + let decl = if include_declaration { def.unwrap_or_default() } else { Vec::new() } .into_iter() - .flatten() .map(|nav| FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() }); let refs = refs.into_iter().flat_map(|(file_id, refs)| { diff --git a/src/tests.rs b/src/tests.rs index e861ff1f..9ccc2b0c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -420,6 +420,17 @@ fn request_reference_uris( text: &str, needle: &str, request_id: i32, +) -> Vec { + request_reference_uris_with_include_declaration(client, uri, text, needle, request_id, true) +} + +fn request_reference_uris_with_include_declaration( + client: &Connection, + uri: Url, + text: &str, + needle: &str, + request_id: i32, + include_declaration: bool, ) -> Vec { let request_id = lsp_server::RequestId::from(request_id); client @@ -432,7 +443,7 @@ fn request_reference_uris( text_document: TextDocumentIdentifier { uri }, position: position_of(text, needle), }, - context: lsp_types::ReferenceContext { include_declaration: true }, + context: lsp_types::ReferenceContext { include_declaration }, work_done_progress_params: WorkDoneProgressParams::default(), partial_result_params: Default::default(), }, @@ -3255,3 +3266,61 @@ fn include_expanded_parameter_decls_keep_module_navigation_available() { shutdown_test_server(&client, server_thread); } + +#[test] +fn references_request_respects_include_declaration() { + let temp_dir = TempDir::new("references-include-declaration"); + let rtl_dir = temp_dir.path().join("rtl"); + fs::create_dir_all(&rtl_dir).unwrap(); + + let top_text = "module top;\n child u_child();\nendmodule\n"; + let child_text = "module child();\nendmodule\n"; + + fs::write( + temp_dir.path().join("vide.toml"), + "top_modules = [\"top\"]\nsources = [\"rtl/*.v\"]\ninclude_dirs = [\"rtl\"]\n", + ) + .unwrap(); + let top_path = rtl_dir.join("top.v"); + let child_path = rtl_dir.join("child.v"); + fs::write(&top_path, top_text).unwrap(); + fs::write(&child_path, child_text).unwrap(); + + let root_path = temp_dir.path().to_path_buf(); + let (client, server_thread) = + spawn_test_workspace(root_path, ClientCapabilities::default(), UserConfig::default()); + let top_uri = to_proto::url_from_abs_path(top_path.as_path()).unwrap(); + let child_uri = to_proto::url_from_abs_path(child_path.as_path()).unwrap(); + + open_test_document(&client, top_uri.clone(), top_text); + open_test_document(&client, child_uri.clone(), child_text); + let _ = request_document_diagnostics(&client, top_uri.clone(), 1); + + let refs_with_decl = request_reference_uris_with_include_declaration( + &client, + child_uri.clone(), + child_text, + "child()", + 2, + true, + ); + assert!( + refs_with_decl.contains(&child_uri) && refs_with_decl.contains(&top_uri), + "include_declaration=true should include the declaration and instantiation: {refs_with_decl:?}" + ); + + let refs_without_decl = request_reference_uris_with_include_declaration( + &client, + child_uri.clone(), + child_text, + "child()", + 3, + false, + ); + assert!( + !refs_without_decl.contains(&child_uri) && refs_without_decl.contains(&top_uri), + "include_declaration=false should exclude the declaration while keeping instantiations: {refs_without_decl:?}" + ); + + shutdown_test_server(&client, server_thread); +} From ce737c54ef82e7030df138d3bffe723ff04b0828 Mon Sep 17 00:00:00 2001 From: hongjr03 Date: Fri, 29 May 2026 14:21:07 +0800 Subject: [PATCH 2/4] refactor: keep references behavior client-driven --- editors/vscode/src/extension.ts | 12 ------------ playground/src/lab/lsp-client.ts | 10 ---------- 2 files changed, 22 deletions(-) diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts index a98539eb..08362f11 100644 --- a/editors/vscode/src/extension.ts +++ b/editors/vscode/src/extension.ts @@ -62,14 +62,6 @@ const activeQiheTokens = new Set(); const qiheProgressNotifications = new Map void }>(); let qiheStatusHideTimer: NodeJS.Timeout | undefined; -function referencesRequestOptions( - options: { includeDeclaration: boolean }, -): { includeDeclaration: boolean } { - // Vide surfaces references as actual usages; declarations stay available through - // go to definition / declaration instead of being mixed into the references list. - return options.includeDeclaration ? { ...options, includeDeclaration: false } : options; -} - function log(message: string): void { outputChannel?.appendLine(message); } @@ -657,10 +649,6 @@ async function createClient(context: vscode.ExtensionContext): Promise - next(document, position, referencesRequestOptions(options), token), - }, ...(config.trace !== 'off' && { trace: config.trace }), }; diff --git a/playground/src/lab/lsp-client.ts b/playground/src/lab/lsp-client.ts index 3748abb0..188a4511 100644 --- a/playground/src/lab/lsp-client.ts +++ b/playground/src/lab/lsp-client.ts @@ -14,14 +14,6 @@ import { BrowserMessageReader, BrowserMessageWriter } from "vscode-languageserve const CLIENT_DISPOSED_MESSAGE = "Vide LSP client has been disposed."; -function referencesRequestOptions( - options: { includeDeclaration: boolean }, -): { includeDeclaration: boolean } { - // Match the desktop extension: references should list usages only, while - // definitions remain reachable via definition / declaration navigation. - return options.includeDeclaration ? { ...options, includeDeclaration: false } : options; -} - export function isClientDisposedError(error: unknown): boolean { return error instanceof Error && error.message === CLIENT_DISPOSED_MESSAGE; } @@ -124,8 +116,6 @@ export class VideBrowserClient { handleDiagnostics: (uri, diagnostics, next) => { next(uri, diagnostics); }, - provideReferences: (document, position, options, token, next) => - next(document, position, referencesRequestOptions(options), token), workspace: { configuration: () => [], }, From 409b1559672508348c438ca946ff0a88523cad97 Mon Sep 17 00:00:00 2001 From: hongjr03 Date: Fri, 29 May 2026 14:32:37 +0800 Subject: [PATCH 3/4] feat(vscode): add references declaration setting --- .../docs/en/user-guide/features/references.mdx | 10 ++++++++++ .../content/docs/en/user-guide/vscode-settings.mdx | 8 ++++++-- .../docs/user-guide/features/references.mdx | 10 ++++++++++ .../content/docs/user-guide/vscode-settings.mdx | 8 ++++++-- editors/vscode/package.json | 5 +++++ editors/vscode/package.nls.json | 1 + editors/vscode/package.nls.zh-cn.json | 1 + editors/vscode/src/extension.ts | 14 ++++++++++++++ editors/vscode/test/configuration.test.ts | 1 + 9 files changed, 54 insertions(+), 4 deletions(-) diff --git a/docs/src/content/docs/en/user-guide/features/references.mdx b/docs/src/content/docs/en/user-guide/features/references.mdx index 3773f8a1..4bbbbb13 100644 --- a/docs/src/content/docs/en/user-guide/features/references.mdx +++ b/docs/src/content/docs/en/user-guide/features/references.mdx @@ -14,6 +14,16 @@ Find References answers “where is this symbol used?” In RTL projects, it is Run VS Code's `Find All References` or `Peek References` on a symbol. Vide searches for its usage locations, deduplicates them, and shows them in the references view. +By default, the references view also includes the declaration location so you can confirm where the symbol comes from. If you want usage locations only, add this to VS Code Settings: + +```json +{ + "vide.references.includeDeclaration": false +} +``` + +See [VS Code Settings](../../vscode-settings/#scope) for the full reference. + ## Demo + ## Formatter and Formatting diff --git a/docs/src/content/docs/user-guide/features/references.mdx b/docs/src/content/docs/user-guide/features/references.mdx index 3cea6ca5..632a4e32 100644 --- a/docs/src/content/docs/user-guide/features/references.mdx +++ b/docs/src/content/docs/user-guide/features/references.mdx @@ -14,6 +14,16 @@ import { usageFiles } from '../../../../examples/dailyUse'; 你可以在 VS Code 中执行 `查找所有引用` 或 `查看引用`。Vide 会查找对应符号的使用位置,去重后显示在引用视图里。 +默认情况下,引用结果会把声明位置一起显示,方便你从列表里确认符号是从哪里引入的。如果你只想看真正的使用位置,可以在 VS Code Settings 里写: + +```json +{ + "vide.references.includeDeclaration": false +} +``` + +完整参考见 [VS Code 设置](../../vscode-settings/#scope)。 + ## 演示 + ## Formatter 和 Formatting diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 38863088..3323aae1 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -199,6 +199,11 @@ "default": "private", "description": "%configuration.scope.visibility.description%" }, + "vide.references.includeDeclaration": { + "type": "boolean", + "default": true, + "description": "%configuration.references.includeDeclaration.description%" + }, "vide.formatter.provider": { "type": "string", "enum": [ diff --git a/editors/vscode/package.nls.json b/editors/vscode/package.nls.json index 9128628e..61f12fe2 100644 --- a/editors/vscode/package.nls.json +++ b/editors/vscode/package.nls.json @@ -16,6 +16,7 @@ "configuration.files.watcher.description": "Controls how Vide watches project files.", "configuration.workspace.auto.reload.description": "Automatically refresh project information when project manifests change.", "configuration.scope.visibility.description": "Controls whether symbols inside scopes, except ports, are visible outside those scopes.", + "configuration.references.includeDeclaration.description": "Include declarations when finding references.", "configuration.formatter.provider.enum.verible": "Use an external verible-verilog-format executable. Supports Format Document and Format Selection.", "configuration.formatter.provider.description": "Formatter backend used by Vide.", "configuration.formatter.path.description": "Path to verible-verilog-format when vide.formatter.provider is verible. Leave empty to find it on PATH.", diff --git a/editors/vscode/package.nls.zh-cn.json b/editors/vscode/package.nls.zh-cn.json index ad889f7a..8d151564 100644 --- a/editors/vscode/package.nls.zh-cn.json +++ b/editors/vscode/package.nls.zh-cn.json @@ -16,6 +16,7 @@ "configuration.files.watcher.description": "控制 Vide 如何监视项目文件。", "configuration.workspace.auto.reload.description": "项目配置文件变化时自动刷新项目信息。", "configuration.scope.visibility.description": "控制作用域内除端口以外的符号是否在作用域外可见。", + "configuration.references.includeDeclaration.description": "查找引用时是否包含声明位置。", "configuration.formatter.provider.enum.verible": "使用外部 verible-verilog-format 可执行文件。支持格式化文档和格式化选区。", "configuration.formatter.provider.description": "Vide 使用的格式化后端。", "configuration.formatter.path.description": "当 vide.formatter.provider 为 verible 时,verible-verilog-format 的路径。留空则从 PATH 中查找。", diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts index 08362f11..24774756 100644 --- a/editors/vscode/src/extension.ts +++ b/editors/vscode/src/extension.ts @@ -381,6 +381,14 @@ function readConfiguration(): ServerConfiguration { }; } +function includeDeclarationInReferences(document: vscode.TextDocument): boolean { + return ( + vscode.workspace + .getConfiguration('vide', document) + .get('references.includeDeclaration') ?? true + ); +} + function resolveWorkingDirectory( context: vscode.ExtensionContext, configuredCwd: string | undefined, @@ -649,6 +657,12 @@ async function createClient(context: vscode.ExtensionContext): Promise { + options.includeDeclaration = includeDeclarationInReferences(document); + return await next(document, position, options, token); + }, + }, ...(config.trace !== 'off' && { trace: config.trace }), }; diff --git a/editors/vscode/test/configuration.test.ts b/editors/vscode/test/configuration.test.ts index 3fde3c48..af3e6e34 100644 --- a/editors/vscode/test/configuration.test.ts +++ b/editors/vscode/test/configuration.test.ts @@ -90,6 +90,7 @@ test('contributes settings for the complete Vide user configuration surface', () 'vide.files.watcher', 'vide.workspace.auto.reload', 'vide.scope.visibility', + 'vide.references.includeDeclaration', 'vide.formatter.provider', 'vide.formatter.path', 'vide.formatter.args', From c8e31dc90f300374e83833225cd835118f78cc77 Mon Sep 17 00:00:00 2001 From: hongjr03 Date: Fri, 29 May 2026 14:35:04 +0800 Subject: [PATCH 4/4] docs: move references setting guidance --- .../en/user-guide/features/references.mdx | 22 ++++++++++--------- .../docs/user-guide/features/references.mdx | 22 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/docs/src/content/docs/en/user-guide/features/references.mdx b/docs/src/content/docs/en/user-guide/features/references.mdx index 4bbbbb13..3baf09b3 100644 --- a/docs/src/content/docs/en/user-guide/features/references.mdx +++ b/docs/src/content/docs/en/user-guide/features/references.mdx @@ -14,16 +14,6 @@ Find References answers “where is this symbol used?” In RTL projects, it is Run VS Code's `Find All References` or `Peek References` on a symbol. Vide searches for its usage locations, deduplicates them, and shows them in the references view. -By default, the references view also includes the declaration location so you can confirm where the symbol comes from. If you want usage locations only, add this to VS Code Settings: - -```json -{ - "vide.references.includeDeclaration": false -} -``` - -See [VS Code Settings](../../vscode-settings/#scope) for the full reference. - ## Demo