Skip to content

Commit a478378

Browse files
authored
refactor: move more features from server.ts (#727)
1 parent 7d7bc56 commit a478378

File tree

32 files changed

+395
-311
lines changed

32 files changed

+395
-311
lines changed

client/src/extension.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import {
1414
import {consoleError, createClientLog} from "./client-log"
1515
import {getClientConfiguration} from "./client-config"
1616
import {
17-
GetDocumentationAtPositionRequest,
18-
GetTypeAtPositionParams,
19-
GetTypeAtPositionRequest,
20-
GetTypeAtPositionResponse,
17+
DocumentationAtPositionRequest,
18+
TypeAtPositionParams,
19+
TypeAtPositionRequest,
20+
TypeAtPositionResponse,
2121
SetToolchainVersionNotification,
2222
SetToolchainVersionParams,
23-
GetGasConsumptionForSelectionRequest,
24-
GetGasConsumptionForSelectionParams,
25-
GetGasConsumptionForSelectionResponse,
23+
GasConsumptionForSelectionRequest,
24+
GasConsumptionForSelectionParams,
25+
GasConsumptionForSelectionResponse,
2626
SearchByTypeRequest,
2727
SearchByTypeParams,
2828
SearchByTypeResponse,
@@ -376,8 +376,8 @@ Node.js: ${info.environment.nodeVersion ?? "Unknown"}`
376376
},
377377
),
378378
vscode.commands.registerCommand(
379-
GetTypeAtPositionRequest,
380-
async (params: GetTypeAtPositionParams | undefined) => {
379+
TypeAtPositionRequest,
380+
async (params: TypeAtPositionParams | undefined) => {
381381
if (!client) {
382382
return null
383383
}
@@ -400,8 +400,8 @@ Node.js: ${info.environment.nodeVersion ?? "Unknown"}`
400400
}
401401
}
402402

403-
const result = await client.sendRequest<GetTypeAtPositionResponse>(
404-
GetTypeAtPositionRequest,
403+
const result = await client.sendRequest<TypeAtPositionResponse>(
404+
TypeAtPositionRequest,
405405
params,
406406
)
407407

@@ -424,14 +424,14 @@ Node.js: ${info.environment.nodeVersion ?? "Unknown"}`
424424
},
425425
),
426426
vscode.commands.registerCommand(
427-
GetDocumentationAtPositionRequest,
428-
async (params: GetTypeAtPositionParams | undefined) => {
427+
DocumentationAtPositionRequest,
428+
async (params: TypeAtPositionParams | undefined) => {
429429
if (!client || !params) {
430430
return null
431431
}
432432

433-
return client.sendRequest<GetTypeAtPositionResponse>(
434-
GetDocumentationAtPositionRequest,
433+
return client.sendRequest<TypeAtPositionResponse>(
434+
DocumentationAtPositionRequest,
435435
params,
436436
)
437437
},
@@ -992,7 +992,7 @@ async function updateGasStatusBar(editor: vscode.TextEditor): Promise<void> {
992992
}
993993

994994
try {
995-
const params: GetGasConsumptionForSelectionParams = {
995+
const params: GasConsumptionForSelectionParams = {
996996
textDocument: {
997997
uri: editor.document.uri.toString(),
998998
},
@@ -1008,8 +1008,8 @@ async function updateGasStatusBar(editor: vscode.TextEditor): Promise<void> {
10081008
},
10091009
}
10101010

1011-
const result = await client.sendRequest<GetGasConsumptionForSelectionResponse>(
1012-
GetGasConsumptionForSelectionRequest,
1011+
const result = await client.sendRequest<GasConsumptionForSelectionResponse>(
1012+
GasConsumptionForSelectionRequest,
10131013
params,
10141014
)
10151015

server/src/languages/fift/foldings/collect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {Point} from "web-tree-sitter"
66
import type * as lsp from "vscode-languageserver"
77
import {FiftFile} from "@server/languages/fift/psi/FiftFile"
88

9-
export function collectFift(file: FiftFile): FoldingRange[] {
9+
export function provideFiftFoldingRanges(file: FiftFile): FoldingRange[] {
1010
const result: FoldingRange[] = []
1111

1212
const genericFolding = (start: Point, end: Point): lsp.FoldingRange => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type {Node as SyntaxNode} from "web-tree-sitter"
2+
import {FiftFile} from "@server/languages/fift/psi/FiftFile"
3+
import * as lsp from "vscode-languageserver"
4+
import {FiftReferent} from "@server/languages/fift/psi/FiftReferent"
5+
import {asLspRange} from "@server/utils/position"
6+
7+
export function provideFiftReferences(node: SyntaxNode, file: FiftFile): lsp.Location[] | null {
8+
if (node.type !== "identifier") return []
9+
10+
const result = new FiftReferent(node, file).findReferences(false)
11+
if (result.length === 0) return null
12+
13+
return result.map(n => ({
14+
uri: n.file.uri,
15+
range: asLspRange(n.node),
16+
}))
17+
}

server/src/languages/fift/semantic_tokens/collect.ts renamed to server/src/languages/fift/semantic-tokens/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as lsp from "vscode-languageserver"
99
import {FiftReference} from "@server/languages/fift/psi/FiftReference"
1010
import {FiftFile} from "@server/languages/fift/psi/FiftFile"
1111

12-
export function collectFift(
12+
export function provideFiftSemanticTokens(
1313
file: FiftFile,
1414
settings: {
1515
enabled: boolean

server/src/languages/tact/TypeInferer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {Reference} from "@server/languages/tact/psi/Reference"
1818
import {Struct, Message, Fun, Primitive, Contract, Trait} from "@server/languages/tact/psi/Decls"
1919
import {isTypeOwnerNode} from "@server/languages/tact/psi/utils"
2020
import type {Node as SyntaxNode} from "web-tree-sitter"
21-
import {CACHE} from "../../cache"
21+
import {CACHE} from "./cache"
2222
import {index, IndexKey} from "@server/languages/tact/indexes"
2323

2424
export class TypeInferer {
File renamed without changes.

server/src/languages/tact/completion/ReferenceCompletionProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright © 2025 TON Studio
3-
import {ResolveState, ScopeProcessor} from "@server/languages/tact/psi/Reference"
3+
import {ScopeProcessor} from "@server/languages/tact/psi/Reference"
44
import {NamedNode, TactNode} from "@server/languages/tact/psi/TactNode"
55
import {
66
Constant,
@@ -24,6 +24,7 @@ import {MessageTy, StructTy} from "@server/languages/tact/types/BaseTy"
2424
import {tactCodeBlock} from "@server/languages/tact/documentation/documentation"
2525
import {trimPrefix} from "@server/utils/strings"
2626
import {TactFile} from "@server/languages/tact/psi/TactFile"
27+
import {ResolveState} from "@server/psi/ResolveState"
2728

2829
export interface CompletionItemAdditionalInformation {
2930
readonly name: string | undefined

server/src/languages/tact/completion/providers/ReferenceCompletionProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// Copyright © 2025 TON Studio
33
import type {CompletionProvider} from "@server/languages/tact/completion/CompletionProvider"
44
import type {CompletionContext} from "@server/languages/tact/completion/CompletionContext"
5-
import {Reference, ResolveState, ScopeProcessor} from "@server/languages/tact/psi/Reference"
5+
import {Reference, ScopeProcessor} from "@server/languages/tact/psi/Reference"
66
import {ReferenceCompletionProcessor} from "@server/languages/tact/completion/ReferenceCompletionProcessor"
77
import {NamedNode, TactNode} from "@server/languages/tact/psi/TactNode"
88
import {FieldsOwner} from "@server/languages/tact/psi/Decls"
99
import type {CompletionResult} from "@server/languages/tact/completion/WeightedCompletionItem"
10+
import {ResolveState} from "@server/psi/ResolveState"
1011

1112
enum CompletionKind {
1213
ONLY_FIELDS = "ONLY_FIELDS",

server/src/languages/tact/selection-gas-consumption.ts renamed to server/src/languages/tact/custom/selection-gas-consumption.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright © 2025 TON Studio
33
import {
4-
GetGasConsumptionForSelectionParams,
5-
GetGasConsumptionForSelectionResponse,
4+
GasConsumptionForSelectionParams,
5+
GasConsumptionForSelectionResponse,
66
} from "@shared/shared-msgtypes"
77
import {asParserPoint} from "@server/utils/position"
88
import type {Node as SyntaxNode, Point} from "web-tree-sitter"
@@ -13,9 +13,9 @@ import {computeGasConsumption} from "@server/languages/tact/asm/gas"
1313
import {TactFile} from "@server/languages/tact/psi/TactFile"
1414
import {findTactFile} from "@server/files"
1515

16-
export async function selectionGasConsumption(
17-
params: GetGasConsumptionForSelectionParams,
18-
): Promise<GetGasConsumptionForSelectionResponse> {
16+
export async function provideSelectionGasConsumption(
17+
params: GasConsumptionForSelectionParams,
18+
): Promise<GasConsumptionForSelectionResponse> {
1919
try {
2020
const uri = params.textDocument.uri
2121
const file = findTactFile(uri)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type {Node as SyntaxNode} from "web-tree-sitter"
2+
import {TactFile} from "@server/languages/tact/psi/TactFile"
3+
import {Ty} from "@server/languages/tact/types/BaseTy"
4+
import {TypeInferer} from "@server/languages/tact/TypeInferer"
5+
import {Expression} from "@server/languages/tact/psi/TactNode"
6+
import {TypeAtPositionParams, TypeAtPositionResponse} from "@shared/shared-msgtypes"
7+
import {asLspRange, asParserPoint} from "@server/utils/position"
8+
9+
export function provideTactTypeAtPosition(
10+
params: TypeAtPositionParams,
11+
file: TactFile,
12+
): TypeAtPositionResponse {
13+
const cursorPosition = asParserPoint(params.position)
14+
const node = file.rootNode.descendantForPosition(cursorPosition)
15+
if (!node) return {type: null, range: null}
16+
17+
const adjustedNode = getAdjustedNodeForType(node)
18+
19+
const res = findTypeForNode(adjustedNode, file)
20+
if (!res) {
21+
return {
22+
type: "void or unknown",
23+
range: asLspRange(node),
24+
}
25+
}
26+
27+
const {ty, node: actualNode} = res
28+
29+
return {
30+
type: ty.qualifiedName(),
31+
range: asLspRange(actualNode),
32+
}
33+
}
34+
35+
function getAdjustedNodeForType(node: SyntaxNode): SyntaxNode {
36+
const parent = node.parent
37+
if (
38+
parent?.type === "method_call_expression" ||
39+
parent?.type === "static_call_expression" ||
40+
parent?.type === "instance_expression"
41+
) {
42+
return parent
43+
}
44+
45+
return node
46+
}
47+
48+
function findTypeForNode(node: SyntaxNode, file: TactFile): {ty: Ty; node: SyntaxNode} | null {
49+
let nodeForType: SyntaxNode | null = node
50+
while (nodeForType) {
51+
const ty = TypeInferer.inferType(new Expression(nodeForType, file))
52+
if (ty) return {ty, node: nodeForType}
53+
nodeForType = nodeForType.parent
54+
if (nodeForType?.type.includes("statement")) break
55+
}
56+
57+
return null
58+
}

0 commit comments

Comments
 (0)