Skip to content

Commit

Permalink
Add completion suggestions in Elm language service and VSCode extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Dec 8, 2024
1 parent 1cb7a13 commit 345b6ad
Show file tree
Hide file tree
Showing 28 changed files with 930 additions and 275 deletions.
10 changes: 10 additions & 0 deletions implement/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ Expand the Elm compiler and core libraries to support `Float` literals and `Stri

+ Added a framework to integrate the various interfaces we want to use in command-line interface applications (`Platform.CommandLineApp`), including stdIn/stdOut/stdErr streams and environment variables.
+ Introduced the `pine run` command as a common way to run an app.

## 2024-10-26 - Added VSCode Extension and Language Server

Published the first version of the Elm developer tools VSCode extension, with a command to format Elm modules.

## 2024-12-08 - Expanded VSCode Extension and Language Server

+ Added feature: Completions: Shows completion suggestions matching the current context
+ Added feature: Hover tips: Shows type annotations and documentation for a type alias, module, custom type or function

27 changes: 26 additions & 1 deletion implement/Pine.Core/LanguageServerProtocol/ClientCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace Pine.Core.LanguageServerProtocol;
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities
/// </summary>
public record ClientCapabilities(
ClientCapabilitiesWorkspace? Workspace);
ClientCapabilitiesWorkspace? Workspace,
TextDocumentClientCapabilities? TextDocument);

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities
Expand All @@ -19,3 +20,27 @@ public record ClientCapabilitiesWorkspace(
public record DidChangeWatchedFilesClientCapabilities(
bool? DynamicRegistration,
bool? RelativePatternSupport);

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentClientCapabilities
/// </summary>
public record TextDocumentClientCapabilities(
CompletionClientCapabilities? Completion);

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionClientCapabilities
/// </summary>
public record CompletionClientCapabilities(
bool? DynamicRegistration,
CompletionClientCapabilitiesCompletionItem? CompletionItem);


/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionClientCapabilities
/// </summary>
public record CompletionClientCapabilitiesCompletionItem(
bool? SnippetSupport,
bool? CommitCharactersSupport,
bool? DeprecatedSupport,
bool? PreselectSupport);

32 changes: 32 additions & 0 deletions implement/Pine.Core/LanguageServerProtocol/CompletionParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;

namespace Pine.Core.LanguageServerProtocol;

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionParams
/// </summary>
public record CompletionParams(
TextDocumentIdentifier TextDocument,
Position Position,
CompletionContext? Context);

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionContext
/// </summary>
public record CompletionContext();

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItem
/// </summary>
public record CompletionItem(
string Label,
string? SortText,
string? FilterText,
string? InsertText,
string? TextEditText,
string? Detail,
string? Documentation,
bool? Preselect,
bool? Deprecated,
IReadOnlyList<string>? CommitCharacters);

13 changes: 12 additions & 1 deletion implement/Pine.Core/LanguageServerProtocol/ServerCapabilities.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace Pine.Core.LanguageServerProtocol;

/// <summary>
Expand All @@ -7,7 +9,8 @@ public record ServerCapabilities(
bool? DocumentFormattingProvider = null,
TextDocumentSyncKind? TextDocumentSync = null,
ServerCapabilitiesWorkspace? Workspace = null,
bool? HoverProvider = null);
bool? HoverProvider = null,
CompletionOptions? CompletionProvider = null);

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentSyncKind
Expand Down Expand Up @@ -44,3 +47,11 @@ public record WorkspaceFoldersServerCapabilities(
bool? Supported,
bool? ChangeNotifications);

/// <summary>
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionOptions
/// </summary>
public record CompletionOptions(
IReadOnlyList<string>? TriggerCharacters,
IReadOnlyList<string>? AllCommitCharacters,
bool? ResolveProvider);

6 changes: 3 additions & 3 deletions implement/Pine.Core/Pine.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyVersion>0.3.26</AssemblyVersion>
<FileVersion>0.3.26</FileVersion>
<AssemblyVersion>0.3.27</AssemblyVersion>
<FileVersion>0.3.27</FileVersion>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

<PropertyGroup>
<PackageId>Pine.Core</PackageId>
<Version>0.3.26</Version>
<Version>0.3.27</Version>
<Description>The cross-platform Elm runtime environment</Description>
<PackageTags>Functional;Elm;Runtime;Compiler;VM;DBMS</PackageTags>
<RepositoryUrl>https://github.com/pine-vm/pine.git</RepositoryUrl>
Expand Down
7 changes: 4 additions & 3 deletions implement/example-apps/elm-editor/src/Frontend/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,9 @@ updateWorkspaceWithoutCmdToUpdateEditor updateConfig event stateBefore =

LanguageServiceInterface.ProvideDefinitionResponse locationsInFiles ->
provideDefinitionInMonacoEditorCmd locationsInFiles

LanguageServiceInterface.WorkspaceSummaryResponse ->
Cmd.none
in
( stateBefore
, cmd
Expand Down Expand Up @@ -1386,7 +1389,6 @@ updateToProvideHoverRequest request workspaceStateBefore =
{ filePathOpenedInEditor = directoryPath ++ [ fileName ]
, positionLineNumber = request.positionLineNumber
, positionColumn = request.positionColumn
, lineText = request.lineText
}
)
workspaceStateBefore
Expand All @@ -1413,7 +1415,6 @@ updateToProvideDefinitionRequest request workspaceStateBefore =
{ filePathOpenedInEditor = directoryPath ++ [ fileName ]
, positionLineNumber = request.positionLineNumber
, positionColumn = request.positionColumn
, lineText = request.lineText
}
)
workspaceStateBefore
Expand All @@ -1437,7 +1438,7 @@ updateToProvideCompletionItemsRequest request workspaceStateBefore =
(LanguageServiceInterface.ProvideCompletionItemsRequest
{ filePathOpenedInEditor = directoryPath ++ [ fileName ]
, cursorLineNumber = request.cursorLineNumber
, textUntilPosition = request.textUntilPosition
, cursorColumn = request.cursorColumn
}
)
workspaceStateBefore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type alias DidChangeContentEventStruct =

type alias RequestCompletionItemsStruct =
{ uri : String
, textUntilPosition : String
, cursorLineNumber : Int
, cursorColumn : Int
}


Expand Down
Loading

0 comments on commit 345b6ad

Please sign in to comment.