diff --git a/haxe_libraries/language-server-protocol.hxml b/haxe_libraries/language-server-protocol.hxml index 236cb20e..a58e748b 100644 --- a/haxe_libraries/language-server-protocol.hxml +++ b/haxe_libraries/language-server-protocol.hxml @@ -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 \ No newline at end of file diff --git a/haxe_libraries/test-adapter.hxml b/haxe_libraries/test-adapter.hxml index 2551a21a..59e96626 100644 --- a/haxe_libraries/test-adapter.hxml +++ b/haxe_libraries/test-adapter.hxml @@ -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() \ No newline at end of file diff --git a/install.hxml b/install.hxml index a2bce606..2ffe1759 100644 --- a/install.hxml +++ b/install.hxml @@ -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 diff --git a/src/haxeLanguageServer/Configuration.hx b/src/haxeLanguageServer/Configuration.hx index 09fb9632..db07acc2 100644 --- a/src/haxeLanguageServer/Configuration.hx +++ b/src/haxeLanguageServer/Configuration.hx @@ -103,6 +103,7 @@ typedef UserConfig = { var maxCompletionItems:Int; var renameSourceFolders:Array; var disableRefactorCache:Bool; + var disableInlineValue:Bool; var inlayHints:InlayHintConfig; var serverRecording:ServerRecordingConfig; } @@ -204,6 +205,7 @@ class Configuration { maxCompletionItems: 1000, renameSourceFolders: ["src", "source", "Source", "test", "tests"], disableRefactorCache: false, + disableInlineValue: false, inlayHints: { variableTypes: false, parameterNames: false, diff --git a/src/haxeLanguageServer/Context.hx b/src/haxeLanguageServer/Context.hx index 7572ef02..5112d07e 100644 --- a/src/haxeLanguageServer/Context.hx +++ b/src/haxeLanguageServer/Context.hx @@ -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; @@ -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; @@ -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)); } @@ -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); diff --git a/src/haxeLanguageServer/features/haxe/InlineValueFeature.hx b/src/haxeLanguageServer/features/haxe/InlineValueFeature.hx new file mode 100644 index 00000000..a10a97ca --- /dev/null +++ b/src/haxeLanguageServer/features/haxe/InlineValueFeature.hx @@ -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->Void, reject:ResponseError->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 = []; + + 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 = file.findAllIdentifiers(matchLocalScoped); + final inlineValueVars:Array = []; + 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); + } +}