Skip to content

Commit 20181cd

Browse files
committed
added support for InlineValueRequests during debugging, fixes vshaxe/vshaxe#657
1 parent c33ca4c commit 20181cd

File tree

6 files changed

+99
-7
lines changed

6 files changed

+99
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# @install: lix --silent download "gh://github.com/vshaxe/language-server-protocol-haxe#a6baa2ddcd792e99b19398048ef95aa00f0aa1f6" into language-server-protocol/3.17.1/github/a6baa2ddcd792e99b19398048ef95aa00f0aa1f6
2-
-cp ${HAXE_LIBCACHE}/language-server-protocol/3.17.1/github/a6baa2ddcd792e99b19398048ef95aa00f0aa1f6/src
1+
# @install: lix --silent download "gh://github.com/vshaxe/language-server-protocol-haxe#deec0e4e2b1ca334a4ce4c43a4fb47e819f43729" into language-server-protocol/3.17.1/github/deec0e4e2b1ca334a4ce4c43a4fb47e819f43729
2+
-cp ${HAXE_LIBCACHE}/language-server-protocol/3.17.1/github/deec0e4e2b1ca334a4ce4c43a4fb47e819f43729/src
33
-D language-server-protocol=3.17.1

haxe_libraries/test-adapter.hxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# @install: lix --silent download "haxelib:/test-adapter#2.0.7" into test-adapter/2.0.7/haxelib
1+
# @install: lix --silent download "haxelib:/test-adapter#3.0.0" into test-adapter/3.0.0/haxelib
22
-lib json2object
3-
-cp ${HAXE_LIBCACHE}/test-adapter/2.0.7/haxelib/
4-
-D test-adapter=2.0.7
3+
-cp ${HAXE_LIBCACHE}/test-adapter/3.0.0/haxelib/
4+
-D test-adapter=3.0.0
55
--macro _testadapter.Macro.init()

install.hxml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
-lib haxeparser:git:https://github.com/HaxeCheckstyle/haxeparser#a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2
44
-lib hxparse:git:https://github.com/simn/hxparse#876070ec62a4869de60081f87763e23457a3bda8
55
-lib json2object:git:https://github.com/elnabo/json2object#a75859de1e966c09e73591b6c9186086c143fe60
6-
-lib test-adapter:2.0.7
6+
-lib test-adapter:3.0.0
77
-lib utest:git:https://github.com/haxe-utest/utest#bdb5fec4b8e77d9a3c079d9cfb108f29f153721a
88
-lib hxnodejs:git:https://github.com/HaxeFoundation/hxnodejs#504066d
99
-lib tokentree:1.2.17
10-
-lib language-server-protocol:git:https://github.com/vshaxe/language-server-protocol-haxe#a6baa2ddcd792e99b19398048ef95aa00f0aa1f6
10+
-lib language-server-protocol:git:https://github.com/vshaxe/language-server-protocol-haxe#deec0e4e2b1ca334a4ce4c43a4fb47e819f43729
1111
-lib hxjsonast:1.1.0
1212
-lib vscode-json-rpc:git:https://github.com/vshaxe/vscode-json-rpc#0160f06bc9df1dd0547f2edf23753540db74ed5b
1313
-lib rename:3.0.0

src/haxeLanguageServer/Configuration.hx

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ typedef UserConfig = {
103103
var maxCompletionItems:Int;
104104
var renameSourceFolders:Array<String>;
105105
var disableRefactorCache:Bool;
106+
var disableInlineValue:Bool;
106107
var inlayHints:InlayHintConfig;
107108
var serverRecording:ServerRecordingConfig;
108109
}
@@ -204,6 +205,7 @@ class Configuration {
204205
maxCompletionItems: 1000,
205206
renameSourceFolders: ["src", "source", "Source", "test", "tests"],
206207
disableRefactorCache: false,
208+
disableInlineValue: false,
207209
inlayHints: {
208210
variableTypes: false,
209211
parameterNames: false,

src/haxeLanguageServer/Context.hx

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import haxeLanguageServer.features.haxe.GotoDefinitionFeature;
2222
import haxeLanguageServer.features.haxe.GotoImplementationFeature;
2323
import haxeLanguageServer.features.haxe.GotoTypeDefinitionFeature;
2424
import haxeLanguageServer.features.haxe.InlayHintFeature;
25+
import haxeLanguageServer.features.haxe.InlineValueFeature;
2526
import haxeLanguageServer.features.haxe.RefactorFeature;
2627
import haxeLanguageServer.features.haxe.RenameFeature;
2728
import haxeLanguageServer.features.haxe.SignatureHelpFeature;
@@ -42,6 +43,7 @@ import languageServerProtocol.protocol.ColorProvider.DocumentColorRequest;
4243
import languageServerProtocol.protocol.FoldingRange.FoldingRangeRequest;
4344
import languageServerProtocol.protocol.Implementation;
4445
import languageServerProtocol.protocol.InlayHints;
46+
import languageServerProtocol.protocol.InlineValue.InlineValueRequest;
4547
import languageServerProtocol.protocol.Messages.ProtocolRequestType;
4648
import languageServerProtocol.protocol.Progress;
4749
import languageServerProtocol.protocol.TypeDefinition.TypeDefinitionRequest;
@@ -302,6 +304,12 @@ class Context {
302304
capabilities.inlayHintProvider = true;
303305
}
304306

307+
if (textDocument?.inlineValue?.dynamicRegistration == true) {
308+
register(InlineValueRequest.type, haxeSelector);
309+
} else {
310+
capabilities.inlineValueProvider = true;
311+
}
312+
305313
resolve({capabilities: capabilities});
306314
languageServerProtocol.sendRequest(RegistrationRequest.type, {registrations: registrations}, null, _ -> {}, error -> trace(error));
307315
}
@@ -385,6 +393,7 @@ class Context {
385393
new CodeActionFeature(this);
386394
new CodeLensFeature(this);
387395
new WorkspaceSymbolsFeature(this);
396+
new InlineValueFeature(this, refactorCache);
388397

389398
for (doc in documents) {
390399
publishDiagnostics(doc.uri);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package haxeLanguageServer.features.haxe;
2+
3+
import haxeLanguageServer.features.haxe.refactoring.EditDoc;
4+
import haxeLanguageServer.features.haxe.refactoring.EditList;
5+
import haxeLanguageServer.features.haxe.refactoring.RefactorCache;
6+
import jsonrpc.CancellationToken;
7+
import jsonrpc.ResponseError;
8+
import jsonrpc.Types.NoData;
9+
import languageServerProtocol.Types.InlineValue;
10+
import languageServerProtocol.protocol.InlineValue;
11+
import refactor.discover.Identifier;
12+
13+
class InlineValueFeature {
14+
final context:Context;
15+
final refactorCache:RefactorCache;
16+
17+
public final converter:Haxe3DisplayOffsetConverter;
18+
19+
public function new(context:Context, refactorCache:RefactorCache) {
20+
this.context = context;
21+
this.refactorCache = refactorCache;
22+
23+
converter = new Haxe3DisplayOffsetConverter();
24+
25+
context.languageServerProtocol.onRequest(InlineValueRequest.type, onInlineValue);
26+
}
27+
28+
function onInlineValue(params:InlineValueParams, token:CancellationToken, resolve:Array<InlineValue>->Void, reject:ResponseError<NoData>->Void) {
29+
if (context.config.user.disableRefactorCache || context.config.user.disableInlineValue) {
30+
resolve([]);
31+
return;
32+
}
33+
34+
var file = refactorCache.fileList.getFile(params.textDocument.uri.toFsPath().toString());
35+
if (file == null) {
36+
reject.handler()("file not found");
37+
return;
38+
}
39+
40+
var editDoc = new EditDoc(params.textDocument.uri.toFsPath(), new EditList(), context, converter);
41+
42+
var localScopedNames:Array<String> = [];
43+
44+
function matchLocalScoped(identifier:Identifier):Bool {
45+
return switch (identifier.type) {
46+
case ScopedLocal(scopeStart, scopeEnd, scopeType):
47+
localScopedNames.push(identifier.name);
48+
true;
49+
case Access: true;
50+
default: false;
51+
}
52+
}
53+
final identifiers:Array<Identifier> = file.findAllIdentifiers(matchLocalScoped);
54+
final inlineValueVars:Array<InlineValue> = [];
55+
for (identifier in identifiers) {
56+
var identifierRange = editDoc.posToRange(identifier.pos);
57+
if (!params.range.contains(identifierRange)) {
58+
continue;
59+
}
60+
var needsExpression:Bool = identifier.name.contains(".");
61+
if ((identifier.type == Access) && !localScopedNames.contains(identifier.name)) {
62+
needsExpression = true;
63+
}
64+
65+
if (needsExpression) {
66+
inlineValueVars.push({
67+
range: identifierRange,
68+
expression: identifier.name
69+
});
70+
} else {
71+
inlineValueVars.push({
72+
range: identifierRange,
73+
variableName: identifier.name,
74+
caseSensitiveLookup: true
75+
});
76+
}
77+
}
78+
79+
resolve(inlineValueVars);
80+
}
81+
}

0 commit comments

Comments
 (0)