GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit d58bc75b authored by Daniel Espinosa Ortiz's avatar Daniel Espinosa Ortiz

lsp: implement basics for a client interface

parent b0f07940
......@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Jsonrpc;
using GLib;
using Json;
public interface GVls.ClientLsp : Jsonrpc.Client
{
......@@ -23,10 +25,135 @@ public interface GVls.ClientLsp : Jsonrpc.Client
public abstract IOStream stream { get; internal set; }
public abstract bool initialized { get; internal set; }
public abstract bool connected { get; internal set; }
public virtual void connect (IOStream stream)
public abstract Container request { get; }
public abstract Cancellable cancellable { get; set; }
public virtual void connect (IOStream stream, string? path) throws GLib.Error
requires (workspace != null)
{
this.stream = stream;
//call ("initialize", )
var rqi = new RequestItem ("initialize");
var pars = new GInitializeParams ();
Variant @params = new Variant.string (Json.gobject_to_data (pars, null));
Variant response = null;
call (rqi.method, @params, cancellable, out response);
}
}
public class GVls.RequestItem : GLib.Object, ContainerHashable {
public string method { get; set; }
public string id { get; set; }
public RequestItem (string method) {
this.method = method;
this.id = Uuid.string_random ();
}
public string hash () { return id; }
public bool equal (GLib.Object obj) {
if (!(obj is RequestItem)) return false;
if ((obj as RequestItem).id == id) return true;
return false;
}
}
public class GVls.GInitializeParams : GLib.Object, InitializeParams {
public int process_id { get; set; }
[Version (deprecated=true)]
public string? root_path { get; set; }
public string root_uri { get; set; }
public GLib.Object? initialization_options { get; set; }
public ClientCapabilities capabilities { get; set; }
public string? trace { get; set; }
public Container? workspaceFolders { get; set; }
construct {
root_path = null;
root_uri = "file:///stdin";
capabilities = new GClientCapabilities ();
}
}
public class GVls.GClientCapabilities : GLib.Object, ClientCapabilities {
[CCode (nick="workspace")]
public WorkspaceClientCapabilities? workspace { get; set; }
[CCode (nick="textDocument")]
public TextDocumentClientCapabilities text_document { get; set; }
[CCode (nick="experimental")]
public GLib.Object experimental { get; set; }
construct {
workspace = new GWorkspaceClientCapabilities ();
text_document = new GTextDocumentClientCapabilities ();
}
}
public class GVls.GWorkspaceClientCapabilities : GLib.Object, WorkspaceClientCapabilities {
[CCode (nick="applyEdit")]
public bool apply_edit { get; set; }
[CCode (nick="workspaceEdit")]
public WorkspaceClientCapabilities.WorkspaceEdit? workspace_edit { get; set; }
[CCode (nick="didChangeConfiguration")]
public WorkspaceClientCapabilities.DidChangeConfiguration? did_change_configuration { get; set; }
[CCode (nick="didChangeWhatchedFile")]
public WorkspaceClientCapabilities.DidChangeWatchedFiles? did_change_watched_files { get; set; }
[CCode (nick="symbol")]
public WorkspaceClientCapabilities.Symbol symbol { get; set; }
[CCode (nick="executeCommand")]
public WorkspaceClientCapabilities.ExecuteCommand execute_command { get; set; }
[CCode (nick="workspaceFolders")]
public bool workspace_folders { get; set; }
[CCode (nick="configuration")]
public bool configuration { get; set; }
}
public class GVls.GTextDocumentClientCapabilities : GLib.Object, TextDocumentClientCapabilities {
[CCode (nick="synchronization")]
public TextDocumentClientCapabilities.Synchronization synchronization { get; set; }
[CCode (nick="completion")]
public TextDocumentClientCapabilities.Completion completion { get; set; }
[CCode (nick="hover")]
public TextDocumentClientCapabilities.Hover hover { get; set; }
[CCode (nick="signatureHelp")]
public TextDocumentClientCapabilities.SignatureHelp signature_help { get; set; }
[CCode (nick="references")]
public TextDocumentClientCapabilities.References references { get; set; }
[CCode (nick="documentHighlight")]
public TextDocumentClientCapabilities.DocumentHighlight document_highlight { get; set; }
[CCode (nick="documentSymbol")]
public TextDocumentClientCapabilities.DocumentSymbol documentSymbol { get; set; }
[CCode (nick="formatting")]
public TextDocumentClientCapabilities.Formating formatting { get; set; }
[CCode (nick="rangeFormatting")]
public TextDocumentClientCapabilities.RangeFormatting range_formatting { get; set; }
[CCode (nick="onTypeFormatting")]
public TextDocumentClientCapabilities.OnTypeFormatting on_type_formatting { get; set; }
[CCode (nick="definition")]
public TextDocumentClientCapabilities.Definition definition { get; set; }
[CCode (nick="typeDefinition")]
public TextDocumentClientCapabilities.TypeDefinition type_definition { get; set; }
[CCode (nick="implementation")]
public TextDocumentClientCapabilities.Implementation implementation { get; set; }
[CCode (nick="codeAction")]
public TextDocumentClientCapabilities.CodeAction codeAction { get; set; }
[CCode (nick="codeLens")]
public TextDocumentClientCapabilities.CodeLens code_lens { get; set; }
[CCode (nick="documentLink")]
public TextDocumentClientCapabilities.DocumentLink document_link { get; set; }
[CCode (nick="colorProvider")]
public TextDocumentClientCapabilities.ColorProvider colorProvider { get; set; }
[CCode (nick="rename")]
public TextDocumentClientCapabilities.Rename rename { get; set; }
[CCode (nick="publishDiagnostics")]
public TextDocumentClientCapabilities.PublishDiagnostics publish_diagnostics { get; set; }
[CCode (nick="foldingRange")]
public TextDocumentClientCapabilities.FoldingRange foldingRange { get; set; }
construct {
completion = new TextDocumentClientCapabilities.Completion ();
documentSymbol = new TextDocumentClientCapabilities.DocumentSymbol ();
}
}
......@@ -152,10 +152,18 @@ public enum GVls.CodeActionKind {
}
}
public class GVls.CodeActionKindObject {
public CodeActionKind kind { get; set; }
public class GVls.CodeActionKindObject : GVls.EnumObject {
construct {
enum_type = typeof (CodeActionKind);
}
public CodeActionKindObject (CodeActionKind kind) {
val = kind;
}
public CodeActionKind get_enum () { return (CodeActionKind) val; }
public override string to_string () { return ((CodeActionKind) val).to_string (); }
}
/**
* Contains additional diagnostic information about the context in which
* a code action is run.
......
......@@ -635,6 +635,18 @@ public enum GVls.MarkupKind {
}
}
public class GVls.MarkupKindObject : GVls.EnumObject {
construct {
enum_type = typeof (MarkupKind);
}
public MarkupKindObject (MarkupKind kind) {
val = kind;
}
public MarkupKind get_enum () { return (MarkupKind) val; }
public override string to_string () { return ((MarkupKind) val).to_string (); }
}
/**
* A `MarkupContent` literal represents a string value which content is interpreted base on its
* kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
......@@ -751,3 +763,129 @@ public interface GVls.DocumentSymbol : Object {
public abstract Container children { get; }
}
/**
* The kind of a completion entry.
*/
public enum CompletionItemKind {
UNKNOWN,
TEXT,
METHOD,
FUNCTION,
CONSTRUCTOR,
FIELD,
VARIABLE,
CLASS,
INTERFACE,
MODULE,
PROPERTY,
UNIT,
VALUE,
ENUM,
KEYWORD,
SNIPPET,
COLOR,
FILE,
REFERENCE,
FOLDER,
ENUMMEMBER,
CONSTANT,
STRUCT,
EVENT,
OPERATOR,
TYPEPARAMETER;
public string to_string () {
string str = "";
switch (this) {
case TEXT:
str = "Text";
break;
case METHOD:
str = "Method";
break;
case FUNCTION:
str = "Function";
break;
case CONSTRUCTOR:
str = "Constructor";
break;
case FIELD:
str = "Field";
break;
case VARIABLE:
str = "Variable";
break;
case CLASS:
str = "Class";
break;
case INTERFACE:
str = "Interface";
break;
case MODULE:
str = "Module";
break;
case PROPERTY:
str = "Property";
break;
case UNIT:
str = "Unit";
break;
case VALUE:
str = "Value";
break;
case ENUM:
str = "Enum";
break;
case KEYWORD:
str = "Keyword";
break;
case SNIPPET:
str = "SNIPPET";
break;
case COLOR:
str = "Color";
break;
case FILE:
str = "File";
break;
case REFERENCE:
str = "Reference";
break;
case FOLDER:
str = "Folder";
break;
case ENUMMEMBER:
str = "EnumMember";
break;
case CONSTANT:
str = "Constant";
break;
case STRUCT:
str = "Struct";
break;
case EVENT:
str = "Event";
break;
case OPERATOR:
str = "Operator";
break;
case TYPEPARAMETER:
str = "TypeParameter";
break;
case UNKNOWN:
str = "Unknown";
break;
}
return str;
}
}
public class GVls.CompletionItemKindObject : GVls.EnumObject {
construct {
enum_type = typeof (CompletionItemKind);
}
public CompletionItemKindObject (CompletionItemKind kind) {
val = kind;
}
public CompletionItemKind get_enum () { return (CompletionItemKind) val; }
public override string to_string () { return ((CompletionItemKind) val).to_string (); }
}
/* gvls-enum.vala
*
* Copyright 2018 Daniel Espinosa <esodan@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class GVls.EnumObject : Object {
public Type enum_type { get; set; }
public int val { get; set; }
construct {
val = 0;
enum_type = Type.INVALID;
}
public virtual string to_string () {
return val.to_string ();
}
}
/* gvls-workspace.vala
*
* Copyright 2018 Daniel Espinosa <esodan@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public interface GVls.InitializeParams : Object {
/**
* The process Id of the parent process that started
* the server. Is null if the process has not been started by another process.
* If the parent process is not alive then the server should exit (see exit notification) its process.
*/
public abstract int process_id { get; set; }
/**
* The rootPath of the workspace. Is null
* if no folder is open.
*
* @deprecated in favour of rootUri.
*/
[Version (deprecated=true)]
public abstract string? root_path { get; set; }
/**
* The rootUri of the workspace. Is null if no
* folder is open. If both `rootPath` and `rootUri` are set
* `rootUri` wins.
*/
public abstract string root_uri { get; set; }
/**
* User provided initialization options.
*/
public abstract Object? initialization_options { get; set; }
/**
* The capabilities provided by the client (editor or tool)
*/
public abstract ClientCapabilities capabilities { get; set; }
/**
* The initial trace setting. If omitted trace is disabled ('off').
*
* Valid values are: 'off' | 'messages' | 'verbose'
*/
public abstract string? trace { get; set; }
/**
* The workspace folders configured in the client when the server starts.
* This property is only available if the client supports workspace folders.
* It can be `null` if the client supports workspace folders but none are
* configured.
*
* A container with objects of type {@link WorkspaceFolder}
*
* Since 3.6.0
*/
public abstract Container? workspaceFolders { get; set; }
}
public interface GVls.ClientCapabilities : Object {
/**
* Workspace specific client capabilities.
*/
[CCode (nick="workspace")]
public abstract WorkspaceClientCapabilities? workspace { get; set; }
/**
* Text document specific client capabilities.
*/
[CCode (nick="textDocument")]
public abstract TextDocumentClientCapabilities text_document { get; set; }
/**
* Experimental client capabilities.
*/
[CCode (nick="experimental")]
public abstract GLib.Object experimental { get; set; }
}
public enum GVls.ResourceOperationKind {
UNKNOWN,
CREATE,
RENAME,
DELETE;
public string to_string () {
string str = "";
switch (this) {
case CREATE:
str = "create";
break;
case RENAME:
str = "rename";
break;
case DELETE:
str = "delete";
break;
case UNKNOWN:
str = "unknown";
break;
}
return str;
}
}
public class GVls.ResourceOperationKindObject : GVls.EnumObject {
construct {
enum_type = typeof (ResourceOperationKind);
}
public ResourceOperationKindObject (ResourceOperationKind kind) {
val = kind;
}
public ResourceOperationKind get_enum () { return (ResourceOperationKind) val; }
public override string to_string () { return ((ResourceOperationKind) val).to_string (); }
}
public enum GVls.FailureHandlingKind {
UNKNOWN,
ABORT,
TRANSACTIONAL,
TEXT_ONLY_TRANSACTIONAL,
UNDO;
public string to_string () {
string str = "";
switch (this) {
case ABORT:
str = "abort";
break;
case TRANSACTIONAL:
str = "transactional";
break;
case TEXT_ONLY_TRANSACTIONAL:
str = "textOnlyTransactional";
break;
case UNDO:
str = "undo";
break;
case UNKNOWN:
str = "unknown";
break;
}
return str;
}
}
/**
* Workspace specific client capabilities.
*/
public interface GVls.WorkspaceClientCapabilities : Object {
/**
* The client supports applying batch edits to the workspace by supporting
* the request 'workspace/applyEdit'
*/
[CCode (nick="applyEdit")]
public abstract bool apply_edit { get; set; }
/**
* Capabilities specific to `WorkspaceEdit`s
*/
[CCode (nick="workspaceEdit")]
public abstract WorkspaceEdit? workspace_edit { get; set; }
public class WorkspaceEdit : Object {
construct {
resource_operations = new GContainer ();
resource_operations.add (new ResourceOperationKindObject (ResourceOperationKind.CREATE));
resource_operations.add (new ResourceOperationKindObject (ResourceOperationKind.RENAME));
resource_operations.add (new ResourceOperationKindObject (ResourceOperationKind.DELETE));
}
/**
* The client supports versioned document changes in `WorkspaceEdit`s
*/
[CCode (nick="documentChanges")]
public bool document_changes { get; set; }
/**
* The resource operations the client supports. Clients should at least
* support 'create', 'rename' and 'delete' files and folders.
*
* Container hold objects of type {@link ResourceOperationKindObject}
*/
[CCode (nick="resourceOperations")]
public Container? resource_operations { get; set; }
/**
* The failure handling strategy of a client if applying the workspace edit
* fails.
*/
[CCode (nick="failureHandling")]
public FailureHandlingKind failure_handling { get; set; }
}
/**
* Capabilities specific to the `workspace/didChangeConfiguration` notification.
*/
[CCode (nick="didChangeConfiguration")]
public abstract DidChangeConfiguration? did_change_configuration { get; set; }
public class DidChangeConfiguration : Object {
/**
* Did change configuration notification supports dynamic registration.
*/
[CCode (nick="dynamicRegistration")]
public bool dynamic_registration { get; set; }
}
/**
* Capabilities specific to the `workspace/didChangeWatchedFiles` notification.
*/
[CCode (nick="didChangeWathedFiles")]
public abstract DidChangeWatchedFiles? did_change_watched_files { get; set; }
public class DidChangeWatchedFiles : Object {
/**
* Did change watched files notification supports dynamic registration.
*/
[CCode (nick="dynamicRegistration")]
public bool dynamic_registration { get; set; }
}
/**
* Capabilities specific to the `workspace/symbol` request.
*/
[CCode (nick="symbol")]
public abstract Symbol symbol { get; set; }
public class Symbol : Object {
/**
* Symbol request supports dynamic registration.
*/
[CCode (nick="dynamicRegistration")]
public bool dynamic_registration { get; set; }
/**
* Specific capabilities for the `SymbolKind` in the `workspace/symbol` request.
*/
[CCode (nick="symbolKind")]
public SymbolKind symbol_kind { get; set; }
}
public class SymbolKind : Object {
/**
* The symbol kind values the client supports. When this
* property exists the client also guarantees that it will
* handle values outside its set gracefully and falls back
* to a default value when unknown.
*
* If this property is not present the client only supports
* the symbol kinds from `File` to `Array` as defined in
* the initial version of the protocol.
*
* Container holds items of type {@link GVls.SymbolKindObject}
*/
[CCode (nick="valueSet")]
public Container value_set { get; set; }
}
/**
* Capabilities specific to the `workspace/executeCommand` request.
*/
[CCode (nick="executeCommand")]
public abstract ExecuteCommand execute_command { get; set; }
public class ExecuteCommand : Object {
/**
* Execute command supports dynamic registration.
*/
[CCode (nick="dynamicRegistration")]
public bool dynamic_registration { get; set; }
}
/**
* The client has support for workspace folders.
*
* Since 3.6.0
*/
[CCode (nick="workspaceFolders")]
public abstract bool workspace_folders { get; set; }
/**
* The client supports `workspace/configuration` requests.
*
* Since 3.6.0
*/
[CCode (nick="configuration")]
public abstract bool configuration { get; set; }
}
......@@ -165,3 +165,14 @@ public enum GVls.SymbolKind {
return str;
}
}
public class GVls.SymbolKindObject : GVls.EnumObject {
construct {
enum_type = typeof (SymbolKind);
}
public SymbolKindObject (SymbolKind kind) {
val = kind;
}
public SymbolKind get_enum () { return (SymbolKind) val; }
public override string to_string () { return ((SymbolKind) val).to_string (); }
}
/* gvls-test-document-capabilities.vala
*
* Copyright 2018 Daniel Espinosa <esodan@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Text document specific client capabilities.
*/
public interface GVls.TextDocumentClientCapabilities : Object {
[CCode (nick="synchronization")]
public abstract Synchronization synchronization { get; set; }
public class Synchronization : Object {
/**
* Whether text document synchronization supports dynamic registration.
*/
[CCode (nick="dynamicRegistration")]