diff --git a/AnyText/AnyText.Lsp/ILspServer.cs b/AnyText/AnyText.Lsp/ILspServer.cs index 994a3337..d7d5c5ac 100644 --- a/AnyText/AnyText.Lsp/ILspServer.cs +++ b/AnyText/AnyText.Lsp/ILspServer.cs @@ -1,5 +1,7 @@ using LspTypes; +using Newtonsoft.Json.Linq; using StreamJsonRpc; +using System; using System.Threading; namespace NMF.AnyText @@ -7,28 +9,38 @@ namespace NMF.AnyText public interface ILspServer { [JsonRpcMethod(Methods.TextDocumentDidChangeName)] - void DidChange(DidChangeTextDocumentParams changes); + void DidChange(JToken arg); [JsonRpcMethod(Methods.TextDocumentDidCloseName)] void DidClose(DidCloseTextDocumentParams closeParams); [JsonRpcMethod(Methods.TextDocumentDidOpenName)] - void DidOpen(DidOpenTextDocumentParams openParams); + void DidOpen(JToken arg); [JsonRpcMethod(Methods.TextDocumentDidSaveName)] - void DidSave(DidSaveTextDocumentParams saveParams); + void DidSave(TextDocumentIdentifier textDocument, string text); [JsonRpcMethod(Methods.ExitName)] void Exit(); [JsonRpcMethod(Methods.InitializeName)] - InitializeResult Initialize(InitializeParams @params); + public InitializeResult Initialize( + int? processId + , _InitializeParams_ClientInfo clientInfo + , string locale + , string rootPath + , Uri rootUri + , ClientCapabilities capabilities + , TraceValue trace + , WorkspaceFolder[] workspaceFolders + , object InitializationOptions = null); [JsonRpcMethod(Methods.InitializedName)] void Initialized(); [JsonRpcMethod(Methods.TextDocumentSemanticTokensFull)] - SemanticTokens QuerySemanticTokens(SemanticTokensParams tokenParams); + + SemanticTokens QuerySemanticTokens(JToken arg); [JsonRpcMethod(Methods.ShutdownName)] void Shutdown(); diff --git a/AnyText/AnyText.Lsp/LspServer.cs b/AnyText/AnyText.Lsp/LspServer.cs index a09cfb78..6e015d6d 100644 --- a/AnyText/AnyText.Lsp/LspServer.cs +++ b/AnyText/AnyText.Lsp/LspServer.cs @@ -1,4 +1,6 @@ using LspTypes; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NMF.AnyText.Grammars; using NMF.Models.Services; using StreamJsonRpc; @@ -6,6 +8,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -25,7 +28,6 @@ public LspServer(params Grammar[] grammars) : this((IEnumerable)grammars) { } - /// /// Creates a new instance /// @@ -35,9 +37,20 @@ public LspServer(IEnumerable grammars) _languages = grammars?.ToDictionary(sp => sp.LanguageId); } - public InitializeResult Initialize(InitializeParams @params) + [JsonRpcMethod(Methods.InitializeName)] + public InitializeResult Initialize( + int? processId + , _InitializeParams_ClientInfo clientInfo + , string locale + , string rootPath + , Uri rootUri + , ClientCapabilities capabilities + , TraceValue trace + , WorkspaceFolder[] workspaceFolders + , object InitializationOptions = null) { - var capabilities = new ServerCapabilities + + var serverCapabilities = new ServerCapabilities { TextDocumentSync = new TextDocumentSyncOptions { @@ -57,7 +70,9 @@ public InitializeResult Initialize(InitializeParams @params) tokenTypes = new[] { "keyword" - } + }, + + } }, ReferencesProvider = new ReferenceOptions @@ -65,20 +80,43 @@ public InitializeResult Initialize(InitializeParams @params) WorkDoneProgress = false } }; - return new InitializeResult { Capabilities = capabilities }; + return new InitializeResult { Capabilities = serverCapabilities }; } - public SemanticTokens QuerySemanticTokens(SemanticTokensParams tokenParams) + public SemanticTokens QuerySemanticTokens(JToken arg) + { + var semanticTokensParams = arg.ToObject(); + string uri = semanticTokensParams.TextDocument.Uri; + + if (!_documents.TryGetValue(uri, out var document)) { + return new SemanticTokens { ResultId = null, Data = Array.Empty() }; + + } + var tokenTypes = document.Context.Grammar.TokenTypes; + var tokenModifiers = document.Context.Grammar.TokenModifiers; + + var tokens = new List(); + return new SemanticTokens + { + ResultId = Guid.NewGuid().ToString(), + Data = tokens.ToArray() + }; + } + public SemanticTokensDelta DeltaSemanticTokens(SemanticTokensParams tokenParams) { return null; } + + public void Initialized() { } public void Shutdown() { } - public void DidChange(DidChangeTextDocumentParams changes) + public void DidChange(JToken arg) { + var changes = arg.ToObject(); + if (changes.ContentChanges == null) return; if (_documents.TryGetValue(changes.TextDocument.Uri, out var document)) { @@ -87,7 +125,7 @@ public void DidChange(DidChangeTextDocumentParams changes) } } - public void DidSave(DidSaveTextDocumentParams saveParams) + public void DidSave(TextDocumentIdentifier textDocument, string text) { } @@ -103,8 +141,10 @@ public void DidClose(DidCloseTextDocumentParams closeParams) } } - public void DidOpen(DidOpenTextDocumentParams openParams) + public void DidOpen(JToken arg) { + var openParams = arg.ToObject(); + var uri = new Uri(openParams.TextDocument.Uri, UriKind.RelativeOrAbsolute); if (uri.IsAbsoluteUri && uri.IsFile) {