Skip to content

Commit d9ebc68

Browse files
authored
feat(find-usages): add setting for "Find Usages" scope (#157)
Fixes #153
1 parent e212dda commit d9ebc68

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@
243243
"type": "boolean",
244244
"default": true,
245245
"description": "Show message fields in document outline"
246+
},
247+
"tact.findUsages.scope": {
248+
"type": "string",
249+
"enum": [
250+
"workspace",
251+
"everywhere"
252+
],
253+
"enumDescriptions": [
254+
"Search only in workspace files (default)",
255+
"Search everywhere including standard library"
256+
],
257+
"default": "workspace",
258+
"description": "Where to search when using Find Usages"
246259
}
247260
}
248261
},

server/src/server.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ connection.onInitialize(async (params: lsp.InitializeParams): Promise<lsp.Initia
868868

869869
connection.onRequest(
870870
lsp.ReferencesRequest.type,
871-
(params: lsp.ReferenceParams): lsp.Location[] | null => {
871+
async (params: lsp.ReferenceParams): Promise<lsp.Location[] | null> => {
872872
const uri = params.textDocument.uri
873873

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

903+
const settings = await getDocumentSettings(file.uri)
904+
if (settings.findUsages.scope === "workspace") {
905+
// filter out references from stdlib
906+
return result
907+
.filter(value => !value.file.fromStdlib && !value.file.fromStubs)
908+
.map(value => ({
909+
uri: value.file.uri,
910+
range: asLspRange(value.node),
911+
}))
912+
}
913+
903914
return result.map(value => ({
904915
uri: value.file.uri,
905916
range: asLspRange(value.node),

server/src/utils/settings.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import {connection} from "@server/connection"
22

3+
export type FindUsagesScope = "workspace" | "everywhere"
4+
35
export interface TactSettings {
46
stdlib: {
57
path: string | null
68
}
9+
findUsages: {
10+
scope: FindUsagesScope
11+
}
712
hints: {
813
types: boolean
914
parameters: boolean
@@ -47,6 +52,9 @@ const defaultSettings: TactSettings = {
4752
stdlib: {
4853
path: null,
4954
},
55+
findUsages: {
56+
scope: "workspace",
57+
},
5058
hints: {
5159
types: true,
5260
parameters: true,
@@ -93,6 +101,9 @@ function mergeSettings(vsSettings: Partial<TactSettings>): TactSettings {
93101
stdlib: {
94102
path: vsSettings.stdlib?.path ?? defaultSettings.stdlib.path,
95103
},
104+
findUsages: {
105+
scope: vsSettings.findUsages?.scope ?? defaultSettings.findUsages.scope,
106+
},
96107
hints: {
97108
types: vsSettings.hints?.types ?? defaultSettings.hints.types,
98109
parameters: vsSettings.hints?.parameters ?? defaultSettings.hints.parameters,

0 commit comments

Comments
 (0)