Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(find-usages): add setting for "Find Usages" scope #157

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@
"type": "boolean",
"default": true,
"description": "Show message fields in document outline"
},
"tact.findUsages.scope": {
"type": "string",
"enum": [
"workspace",
"everywhere"
],
"enumDescriptions": [
"Search only in workspace files (default)",
"Search everywhere including standard library"
],
"default": "workspace",
"description": "Where to search when using Find Usages"
}
}
},
Expand Down
13 changes: 12 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ connection.onInitialize(async (params: lsp.InitializeParams): Promise<lsp.Initia

connection.onRequest(
lsp.ReferencesRequest.type,
(params: lsp.ReferenceParams): lsp.Location[] | null => {
async (params: lsp.ReferenceParams): Promise<lsp.Location[] | null> => {
const uri = params.textDocument.uri

if (uri.endsWith(".fif")) {
Expand Down Expand Up @@ -900,6 +900,17 @@ connection.onInitialize(async (params: lsp.InitializeParams): Promise<lsp.Initia
const result = new Referent(referenceNode, file).findReferences(false)
if (result.length === 0) return null

const settings = await getDocumentSettings(file.uri)
if (settings.findUsages.scope === "workspace") {
// filter out references from stdlib
return result
.filter(value => !value.file.fromStdlib && !value.file.fromStubs)
.map(value => ({
uri: value.file.uri,
range: asLspRange(value.node),
}))
}

return result.map(value => ({
uri: value.file.uri,
range: asLspRange(value.node),
Expand Down
11 changes: 11 additions & 0 deletions server/src/utils/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {connection} from "@server/connection"

export type FindUsagesScope = "workspace" | "everywhere"

export interface TactSettings {
stdlib: {
path: string | null
}
findUsages: {
scope: FindUsagesScope
}
hints: {
types: boolean
parameters: boolean
Expand Down Expand Up @@ -47,6 +52,9 @@ const defaultSettings: TactSettings = {
stdlib: {
path: null,
},
findUsages: {
scope: "workspace",
},
hints: {
types: true,
parameters: true,
Expand Down Expand Up @@ -93,6 +101,9 @@ function mergeSettings(vsSettings: Partial<TactSettings>): TactSettings {
stdlib: {
path: vsSettings.stdlib?.path ?? defaultSettings.stdlib.path,
},
findUsages: {
scope: vsSettings.findUsages?.scope ?? defaultSettings.findUsages.scope,
},
hints: {
types: vsSettings.hints?.types ?? defaultSettings.hints.types,
parameters: vsSettings.hints?.parameters ?? defaultSettings.hints.parameters,
Expand Down