@@ -118,9 +118,14 @@ defmodule NextLS do
118118 save: % SaveOptions { include_text: true } ,
119119 change: TextDocumentSyncKind . full ( )
120120 } ,
121- completion_provider: % GenLSP.Structures.CompletionOptions {
122- trigger_characters: [ "." , "@" , "&" , "%" , "^" , ":" , "!" , "-" , "~" ]
123- } ,
121+ completion_provider:
122+ if init_opts . experimental . completions . enabled do
123+ % GenLSP.Structures.CompletionOptions {
124+ trigger_characters: [ "." , "@" , "&" , "%" , "^" , ":" , "!" , "-" , "~" , "/" ]
125+ }
126+ else
127+ nil
128+ end ,
124129 document_formatting_provider: true ,
125130 hover_provider: true ,
126131 workspace_symbol_provider: true ,
@@ -516,7 +521,8 @@ defmodule NextLS do
516521 |> Enum . take ( position . line + 1 )
517522 |> Enum . reverse ( )
518523 |> then ( fn [ last_line | rest ] ->
519- [ String . slice ( last_line , 1 .. ( position . character + 1 ) ) | rest ]
524+ { line , _forget } = String . split_at ( last_line , position . character )
525+ [ line | rest ]
520526 end )
521527 |> Enum . reverse ( )
522528 |> Enum . join ( "\n " )
@@ -541,6 +547,9 @@ defmodule NextLS do
541547 :function -> { "#{ name } /#{ symbol . arity } " , GenLSP.Enumerations.CompletionItemKind . function ( ) , symbol . docs }
542548 :module -> { name , GenLSP.Enumerations.CompletionItemKind . module ( ) , "" }
543549 :variable -> { name , GenLSP.Enumerations.CompletionItemKind . variable ( ) , "" }
550+ :dir -> { name , GenLSP.Enumerations.CompletionItemKind . folder ( ) , "" }
551+ :file -> { name , GenLSP.Enumerations.CompletionItemKind . file ( ) , "" }
552+ :keyword -> { name , GenLSP.Enumerations.CompletionItemKind . field ( ) , "" }
544553 _ -> { name , GenLSP.Enumerations.CompletionItemKind . text ( ) , "" }
545554 end
546555
@@ -552,28 +561,10 @@ defmodule NextLS do
552561 }
553562 end )
554563
555- # results =
556- # for snippet <- [
557- # "defmodule",
558- # "def",
559- # "defp",
560- # "defmacro",
561- # "defmacrop",
562- # "for",
563- # "with",
564- # "case",
565- # "cond",
566- # "defprotocol",
567- # "defimpl",
568- # "defexception",
569- # "defstruct"
570- # ],
571- # item <- List.wrap(NextLS.Snippet.get(snippet, context.trigger_character)),
572- # item do
573- # item
574- # end
575-
576564 { :reply , results , lsp }
565+ rescue
566+ _ ->
567+ { :reply , [ ] , lsp }
577568 end
578569
579570 def handle_request ( % Shutdown { } , lsp ) do
@@ -1091,18 +1082,30 @@ defmodule NextLS do
10911082 # penalty for unmatched letter
10921083 defp calc_unmatched_penalty ( score , _traits ) , do: score - 1
10931084
1085+ defmodule InitOpts.Experimental do
1086+ @ moduledoc false
1087+ defstruct completions: % { enabled: false }
1088+ end
1089+
10941090 defmodule InitOpts do
10951091 @ moduledoc false
10961092 import Schematic
10971093
1098- defstruct mix_target: "host" , mix_env: "dev"
1094+ defstruct mix_target: "host" , mix_env: "dev" , experimental: % NextLS.InitOpts.Experimental { }
10991095
11001096 def validate ( opts ) do
11011097 schematic =
11021098 nullable (
11031099 schema ( __MODULE__ , % {
11041100 optional ( :mix_target ) => str ( ) ,
1105- optional ( :mix_env ) => str ( )
1101+ optional ( :mix_env ) => str ( ) ,
1102+ optional ( :experimental ) =>
1103+ schema ( NextLS.InitOpts.Experimental , % {
1104+ optional ( :completions ) =>
1105+ map ( % {
1106+ { "enabled" , :enabled } => bool ( )
1107+ } )
1108+ } )
11061109 } )
11071110 )
11081111
0 commit comments