Skip to content

Commit

Permalink
Merge pull request #5424 from OceanOak/completion-item-kind
Browse files Browse the repository at this point in the history
 #5423 Followup
  • Loading branch information
StachuDotNet authored Oct 24, 2024
2 parents 1494111 + cfd0407 commit 3f99e8e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 45 deletions.
104 changes: 63 additions & 41 deletions packages/darklang/languageServerProtocol/language/completion.dark
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,63 @@ module Darklang =


module CompletionItem =
module CompletionItemKind =
/// The kind of a completion entry.
type CompletionItemKind =
| 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

let toJson (kind: CompletionItemKind) : Json =
match kind with
| Text -> Json.Number 1.0
| Method -> Json.Number 2.0
| Function -> Json.Number 3.0
| Constructor -> Json.Number 4.0
| Field -> Json.Number 5.0
| Variable -> Json.Number 6.0
| Class -> Json.Number 7.0
| Interface -> Json.Number 8.0
| Module -> Json.Number 9.0
| Property -> Json.Number 10.0
| Unit -> Json.Number 11.0
| Value -> Json.Number 12.0
| Enum -> Json.Number 13.0
| Keyword -> Json.Number 14.0
| Snippet -> Json.Number 15.0
| Color -> Json.Number 16.0
| File -> Json.Number 17.0
| Reference -> Json.Number 18.0
| Folder -> Json.Number 19.0
| EnumMember -> Json.Number 20.0
| Constant -> Json.Number 21.0
| Struct -> Json.Number 22.0
| Event -> Json.Number 23.0
| Operator -> Json.Number 24.0
| TypeParameter -> Json.Number 25.0

/// A completion item represents a text snippet that is
/// proposed to complete text that is being typed.
type CompletionItem =
Expand All @@ -68,9 +125,9 @@ module Darklang =
// /// Additional details for the label
// labelDetails?: CompletionItemLabelDetails;

// /// The kind of this completion item. Based of the kind
// /// an icon is chosen by the editor.
// kind?: CompletionItemKind;
/// The kind of this completion item. Based of the kind
/// an icon is chosen by the editor.
kind: Stdlib.Option.Option<CompletionItemKind.CompletionItemKind>

// /// Tags for this completion item.
// tags?: CompletionItemTag[];
Expand Down Expand Up @@ -183,6 +240,9 @@ module Darklang =
let toJson (item: CompletionItem) : Json =
[ Stdlib.Option.Option.Some(("label", Json.String item.label))

item.kind
|> Stdlib.Option.map (fun k -> ("kind", CompletionItemKind.toJson k))

item.detail |> Stdlib.Option.map (fun d -> ("detail", Json.String d))

item.preselect |> Stdlib.Option.map (fun p -> ("preselect", Json.Bool p))
Expand Down Expand Up @@ -601,44 +661,6 @@ module Darklang =
}


/// The kind of a completion entry.
export namespace CompletionItemKind {
export const Text: 1 = 1;
export const Method: 2 = 2;
export const Function: 3 = 3;
export const Constructor: 4 = 4;
export const Field: 5 = 5;
export const Variable: 6 = 6;
export const Class: 7 = 7;
export const Interface: 8 = 8;
export const Module: 9 = 9;
export const Property: 10 = 10;
export const Unit: 11 = 11;
export const Value: 12 = 12;
export const Enum: 13 = 13;
export const Keyword: 14 = 14;
export const Snippet: 15 = 15;
export const Color: 16 = 16;
export const File: 17 = 17;
export const Reference: 18 = 18;
export const Folder: 19 = 19;
export const EnumMember: 20 = 20;
export const Constant: 21 = 21;
export const Struct: 22 = 22;
export const Event: 23 = 23;
export const Operator: 24 = 24;
export const TypeParameter: 25 = 25;
}
export type CompletionItemKind = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25;










/// The client supports the following `CompletionList` specific capabilities.
export interface CompletionListCapabilities {
Expand Down
18 changes: 14 additions & 4 deletions packages/darklang/languageTools/lsp-server/completions.dark
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ module Darklang =

let createCompletionItem
(label: String)
(kind:
LanguageServerProtocol.Completions.CompletionItem.CompletionItemKind.CompletionItemKind)
(detail: String)
(kind: String)
(insertText: String)
: LanguageServerProtocol.Completions.CompletionItem.CompletionItem =
LanguageServerProtocol.Completions.CompletionItem.CompletionItem
{ label = label
kind = Stdlib.Option.Option.Some kind
detail = Stdlib.Option.Option.Some detail
preselect = Stdlib.Option.Option.Some true
sortText = Stdlib.Option.Option.Some label
Expand All @@ -31,7 +33,7 @@ module Darklang =
// textEdit = Stdlib.Option.Option.None
textEditText = Stdlib.Option.Option.None
commitCharacters = Stdlib.Option.Option.Some [ " " ]
data = Stdlib.Option.Option.Some(Json.String kind) }
data = Stdlib.Option.Option.None }

let createCompletions
(wordUnderCursor: String)
Expand All @@ -48,7 +50,11 @@ module Darklang =
"with"
"fun" ]
|> Stdlib.List.map (fun k ->
createCompletionItem k "keyword" "keyword" k)
createCompletionItem
k
LanguageServerProtocol.Completions.CompletionItem.CompletionItemKind.CompletionItemKind.Keyword
"keyword"
k)

let functions =
(PackageManager.Function.getAllFnNames ())
Expand All @@ -70,7 +76,11 @@ module Darklang =
else
f

createCompletionItem f "function" "function" insertText)
createCompletionItem
f
LanguageServerProtocol.Completions.CompletionItem.CompletionItemKind.CompletionItemKind.Function
"function"
insertText)

let completions = Stdlib.List.flatten [ keywords; functions ]

Expand Down

0 comments on commit 3f99e8e

Please sign in to comment.