Skip to content

Commit

Permalink
change LSP request params
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-hert committed Nov 1, 2024
1 parent 86c811b commit 7d16f59
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
22 changes: 17 additions & 5 deletions AnyText/AnyText.Lsp/ILspServer.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
using LspTypes;
using Newtonsoft.Json.Linq;
using StreamJsonRpc;
using System;
using System.Threading;

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();
Expand Down
58 changes: 49 additions & 9 deletions AnyText/AnyText.Lsp/LspServer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using LspTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NMF.AnyText.Grammars;
using NMF.Models.Services;
using StreamJsonRpc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -25,7 +28,6 @@ public LspServer(params Grammar[] grammars)
: this((IEnumerable<Grammar>)grammars)
{
}

/// <summary>
/// Creates a new instance
/// </summary>
Expand All @@ -35,9 +37,20 @@ public LspServer(IEnumerable<Grammar> 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
{
Expand All @@ -57,28 +70,53 @@ public InitializeResult Initialize(InitializeParams @params)
tokenTypes = new[]
{
"keyword"
}
},


}
},
ReferencesProvider = new ReferenceOptions
{
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<SemanticTokensParams>();
string uri = semanticTokensParams.TextDocument.Uri;

if (!_documents.TryGetValue(uri, out var document)) {
return new SemanticTokens { ResultId = null, Data = Array.Empty<uint>() };

}
var tokenTypes = document.Context.Grammar.TokenTypes;
var tokenModifiers = document.Context.Grammar.TokenModifiers;

var tokens = new List<uint>();
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<DidChangeTextDocumentParams>();

if (changes.ContentChanges == null) return;
if (_documents.TryGetValue(changes.TextDocument.Uri, out var document))
{
Expand All @@ -87,7 +125,7 @@ public void DidChange(DidChangeTextDocumentParams changes)
}
}

public void DidSave(DidSaveTextDocumentParams saveParams)
public void DidSave(TextDocumentIdentifier textDocument, string text)
{
}

Expand All @@ -103,8 +141,10 @@ public void DidClose(DidCloseTextDocumentParams closeParams)
}
}

public void DidOpen(DidOpenTextDocumentParams openParams)
public void DidOpen(JToken arg)
{
var openParams = arg.ToObject<DidOpenTextDocumentParams>();

var uri = new Uri(openParams.TextDocument.Uri, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri && uri.IsFile)
{
Expand Down

0 comments on commit 7d16f59

Please sign in to comment.