-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInlayHintLanguageFeature.ts
67 lines (56 loc) · 2.72 KB
/
InlayHintLanguageFeature.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { InlayHint, InlayHintKind, MarkupKind } from 'vscode-languageserver/node';
import { PhpClassMethodNode } from '../fusion/PhpClassMethodNode';
import { AbstractLanguageFeature } from './AbstractLanguageFeature';
import { LanguageFeatureContext } from './LanguageFeatureContext';
import { ObjectFunctionPathNode } from 'ts-fusion-parser/out/dsl/eel/nodes/ObjectFunctionPathNode';
import { LinePositionedNode } from '../common/LinePositionedNode';
import { LiteralObjectNode } from 'ts-fusion-parser/out/dsl/eel/nodes/LiteralObjectNode';
import { LiteralArrayNode } from 'ts-fusion-parser/out/dsl/eel/nodes/LiteralArrayNode';
import { AbstractLiteralNode } from 'ts-fusion-parser/out/dsl/eel/nodes/AbstractLiteralNode';
import { AbstractNode } from 'ts-fusion-parser/out/common/AbstractNode';
import { InlayHintDepth } from '../ExtensionConfiguration';
import { FusionWorkspace } from '../fusion/FusionWorkspace';
export class InlayHintLanguageFeature extends AbstractLanguageFeature {
protected run({ parsedFile, workspace }: LanguageFeatureContext) {
if (workspace.getConfiguration().inlayHint.depth === InlayHintDepth.Disabled) return null
const inlayHints: InlayHint[] = []
const phpMethodNodes = parsedFile.getNodesByType(PhpClassMethodNode)
if (!phpMethodNodes) return null
for (const phpMethodNode of phpMethodNodes) {
const node = phpMethodNode.getNode()
const eelHelper = workspace.neosWorkspace.getEelHelperTokensByName(node.eelHelper.identifier)
if (!eelHelper) continue
const method = eelHelper.methods.find(method => method.valid(node.identifier))
if (!method) continue
if (!(node.pathNode instanceof ObjectFunctionPathNode)) continue
for (const index in node.pathNode.args) {
const arg = node.pathNode.args[index]
if (!this.canShowInlayHintForArgumentNode(workspace, arg)) continue
const parameter = method.parameters[index]
if (!parameter) continue
const linePositionedArg = arg.linePositionedNode
const hint: InlayHint = {
label: parameter.name.replace("$", "") + ':',
kind: InlayHintKind.Parameter,
tooltip: {
kind: MarkupKind.Markdown,
value: [
"```php",
`<?php`,
`${parameter.type ?? ""}${parameter.name}${parameter.defaultValue ?? ""}`,
"```"
].join("\n")
},
paddingRight: true,
position: linePositionedArg.getBegin()
}
inlayHints.push(hint)
}
}
return inlayHints
}
protected canShowInlayHintForArgumentNode(workspace: FusionWorkspace, argumentNode: AbstractNode) {
if (workspace.getConfiguration().inlayHint.depth === InlayHintDepth.Always) return true
return argumentNode instanceof AbstractLiteralNode || argumentNode instanceof LiteralObjectNode || argumentNode instanceof LiteralArrayNode
}
}