Skip to content

added support for InlineValueRequests during debugging #136

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 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
4 changes: 2 additions & 2 deletions haxe_libraries/language-server-protocol.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "gh://github.com/vshaxe/language-server-protocol-haxe#a6baa2ddcd792e99b19398048ef95aa00f0aa1f6" into language-server-protocol/3.17.1/github/a6baa2ddcd792e99b19398048ef95aa00f0aa1f6
-cp ${HAXE_LIBCACHE}/language-server-protocol/3.17.1/github/a6baa2ddcd792e99b19398048ef95aa00f0aa1f6/src
# @install: lix --silent download "gh://github.com/vshaxe/language-server-protocol-haxe#deec0e4e2b1ca334a4ce4c43a4fb47e819f43729" into language-server-protocol/3.17.1/github/deec0e4e2b1ca334a4ce4c43a4fb47e819f43729
-cp ${HAXE_LIBCACHE}/language-server-protocol/3.17.1/github/deec0e4e2b1ca334a4ce4c43a4fb47e819f43729/src
-D language-server-protocol=3.17.1
6 changes: 3 additions & 3 deletions haxe_libraries/test-adapter.hxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @install: lix --silent download "haxelib:/test-adapter#2.0.7" into test-adapter/2.0.7/haxelib
# @install: lix --silent download "haxelib:/test-adapter#3.0.0" into test-adapter/3.0.0/haxelib
-lib json2object
-cp ${HAXE_LIBCACHE}/test-adapter/2.0.7/haxelib/
-D test-adapter=2.0.7
-cp ${HAXE_LIBCACHE}/test-adapter/3.0.0/haxelib/
-D test-adapter=3.0.0
--macro _testadapter.Macro.init()
4 changes: 2 additions & 2 deletions install.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
-lib haxeparser:git:https://github.com/HaxeCheckstyle/haxeparser#a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2
-lib hxparse:git:https://github.com/simn/hxparse#876070ec62a4869de60081f87763e23457a3bda8
-lib json2object:git:https://github.com/elnabo/json2object#a75859de1e966c09e73591b6c9186086c143fe60
-lib test-adapter:2.0.7
-lib test-adapter:3.0.0
-lib utest:git:https://github.com/haxe-utest/utest#bdb5fec4b8e77d9a3c079d9cfb108f29f153721a
-lib hxnodejs:git:https://github.com/HaxeFoundation/hxnodejs#504066d
-lib tokentree:1.2.17
-lib language-server-protocol:git:https://github.com/vshaxe/language-server-protocol-haxe#a6baa2ddcd792e99b19398048ef95aa00f0aa1f6
-lib language-server-protocol:git:https://github.com/vshaxe/language-server-protocol-haxe#deec0e4e2b1ca334a4ce4c43a4fb47e819f43729
-lib hxjsonast:1.1.0
-lib vscode-json-rpc:git:https://github.com/vshaxe/vscode-json-rpc#0160f06bc9df1dd0547f2edf23753540db74ed5b
-lib rename:3.0.0
Expand Down
2 changes: 2 additions & 0 deletions src/haxeLanguageServer/Configuration.hx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef UserConfig = {
var maxCompletionItems:Int;
var renameSourceFolders:Array<String>;
var disableRefactorCache:Bool;
var disableInlineValue:Bool;
var inlayHints:InlayHintConfig;
var serverRecording:ServerRecordingConfig;
}
Expand Down Expand Up @@ -204,6 +205,7 @@ class Configuration {
maxCompletionItems: 1000,
renameSourceFolders: ["src", "source", "Source", "test", "tests"],
disableRefactorCache: false,
disableInlineValue: false,
inlayHints: {
variableTypes: false,
parameterNames: false,
Expand Down
9 changes: 9 additions & 0 deletions src/haxeLanguageServer/Context.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import haxeLanguageServer.features.haxe.GotoDefinitionFeature;
import haxeLanguageServer.features.haxe.GotoImplementationFeature;
import haxeLanguageServer.features.haxe.GotoTypeDefinitionFeature;
import haxeLanguageServer.features.haxe.InlayHintFeature;
import haxeLanguageServer.features.haxe.InlineValueFeature;
import haxeLanguageServer.features.haxe.RefactorFeature;
import haxeLanguageServer.features.haxe.RenameFeature;
import haxeLanguageServer.features.haxe.SignatureHelpFeature;
Expand All @@ -42,6 +43,7 @@ import languageServerProtocol.protocol.ColorProvider.DocumentColorRequest;
import languageServerProtocol.protocol.FoldingRange.FoldingRangeRequest;
import languageServerProtocol.protocol.Implementation;
import languageServerProtocol.protocol.InlayHints;
import languageServerProtocol.protocol.InlineValue.InlineValueRequest;
import languageServerProtocol.protocol.Messages.ProtocolRequestType;
import languageServerProtocol.protocol.Progress;
import languageServerProtocol.protocol.TypeDefinition.TypeDefinitionRequest;
Expand Down Expand Up @@ -302,6 +304,12 @@ class Context {
capabilities.inlayHintProvider = true;
}

if (textDocument?.inlineValue?.dynamicRegistration == true) {
register(InlineValueRequest.type, haxeSelector);
} else {
capabilities.inlineValueProvider = true;
}

resolve({capabilities: capabilities});
languageServerProtocol.sendRequest(RegistrationRequest.type, {registrations: registrations}, null, _ -> {}, error -> trace(error));
}
Expand Down Expand Up @@ -385,6 +393,7 @@ class Context {
new CodeActionFeature(this);
new CodeLensFeature(this);
new WorkspaceSymbolsFeature(this);
new InlineValueFeature(this, refactorCache);

for (doc in documents) {
publishDiagnostics(doc.uri);
Expand Down
81 changes: 81 additions & 0 deletions src/haxeLanguageServer/features/haxe/InlineValueFeature.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package haxeLanguageServer.features.haxe;

import haxeLanguageServer.features.haxe.refactoring.EditDoc;
import haxeLanguageServer.features.haxe.refactoring.EditList;
import haxeLanguageServer.features.haxe.refactoring.RefactorCache;
import jsonrpc.CancellationToken;
import jsonrpc.ResponseError;
import jsonrpc.Types.NoData;
import languageServerProtocol.Types.InlineValue;
import languageServerProtocol.protocol.InlineValue;
import refactor.discover.Identifier;

class InlineValueFeature {
final context:Context;
final refactorCache:RefactorCache;

public final converter:Haxe3DisplayOffsetConverter;

public function new(context:Context, refactorCache:RefactorCache) {
this.context = context;
this.refactorCache = refactorCache;

converter = new Haxe3DisplayOffsetConverter();

context.languageServerProtocol.onRequest(InlineValueRequest.type, onInlineValue);
}

function onInlineValue(params:InlineValueParams, token:CancellationToken, resolve:Array<InlineValue>->Void, reject:ResponseError<NoData>->Void) {
if (context.config.user.disableRefactorCache || context.config.user.disableInlineValue) {
resolve([]);
return;
}

var file = refactorCache.fileList.getFile(params.textDocument.uri.toFsPath().toString());
if (file == null) {
reject.handler()("file not found");
return;
}

var editDoc = new EditDoc(params.textDocument.uri.toFsPath(), new EditList(), context, converter);

var localScopedNames:Array<String> = [];

function matchLocalScoped(identifier:Identifier):Bool {
return switch (identifier.type) {
case ScopedLocal(scopeStart, scopeEnd, scopeType):
localScopedNames.push(identifier.name);
true;
case Access: true;
default: false;
}
}
final identifiers:Array<Identifier> = file.findAllIdentifiers(matchLocalScoped);
final inlineValueVars:Array<InlineValue> = [];
for (identifier in identifiers) {
var identifierRange = editDoc.posToRange(identifier.pos);
if (!params.range.contains(identifierRange)) {
continue;
}
var needsExpression:Bool = identifier.name.contains(".");
if ((identifier.type == Access) && !localScopedNames.contains(identifier.name)) {
needsExpression = true;
}

if (needsExpression) {
inlineValueVars.push({
range: identifierRange,
expression: identifier.name
});
} else {
inlineValueVars.push({
range: identifierRange,
variableName: identifier.name,
caseSensitiveLookup: true
});
}
}

resolve(inlineValueVars);
}
}
Loading