@@ -294,7 +294,7 @@ type lex_token = {
294294};
295295
296296type completable_context =
297- | CompletableInclude (string )
297+ | CompletableInclude (string , bool )
298298 | CompletableStatement (bool )
299299 | CompletableExpressionWithReturn
300300 | CompletableExpression
@@ -307,7 +307,7 @@ type completable_context =
307307let print_string_of_context = context => {
308308 let ctx =
309309 switch (context) {
310- | CompletableInclude (_ ) => "CompleteInclude"
310+ | CompletableInclude (_ , _ ) => "CompleteInclude"
311311 | CompletableAs => "CompleteAs"
312312 | CompletableAfterLet => "CompletableAfterLet"
313313 | CompletableExpressionWithReturn => "CompletableExpressionWithReturn"
@@ -449,38 +449,50 @@ let get_completion_context = (documents, uri, position: Protocol.position) => {
449449 tokens: list (lex_token ),
450450 ) => {
451451 switch (tokens) {
452- // TODO: Add a state for when we are at from |
453- // TODO: Add a state for when we are at from XXXX use { | }
454452 // TODO: Add a state for when we are at match (XXXX) { | } <- This could be very useful also could not be
455453 // TODO: Add a state for type XXXX = |
454+ // TODO: Add state for use XXXX.
456455 // Tokens that we care about
457456 | [ {token: Parser . LET }, ... _ ]
458457 when ! hit_eol && token_non_breaking_lst(token_list) =>
459458 CompletableAfterLet
460- | [ {token: Parser . STRING (_ ), end_loc}, {token: Parser . INCLUDE }, ... _ ]
459+ // TODO: Reimplement the as completion
460+ | [ {token: Parser . STRING (str ), end_loc}, {token: Parser . FROM }, ... _ ]
461461 when
462462 ! hit_eol
463463 && after_range(end_loc, offset)
464464 && ! last_token_eq(Parser . AS , token_list) =>
465- CompletableAs
465+ CompletableInclude (str , true )
466466 | [
467467 {token: Parser . STRING (str ), start_loc, end_loc},
468- {token: Parser . INCLUDE },
468+ {token: Parser . FROM },
469469 ... _ ,
470470 ]
471471 when in_range(start_loc, end_loc, offset) =>
472- CompletableInclude (str)
472+ CompletableInclude (str, false )
473+ // TODO: Just capture up to the .
473474 | [ {token: Parser . DOT }, {token: Parser . EOL }, ... _ ]
474475 when ! hit_eol && ! last_token_eq(Parser . DOT , token_list) =>
475- // TODO: Support test().label on records somehow
476+ /*
477+ * TODO: Support test().label on records somehow
478+ * This is going to require using sourceTree, to get the return type of the function, (We may also be able to check the env but the problem is we don't have a complete env at this point)
479+ * After we have a type signature it shouldn't be that hard to resolve the completions, until that point it is though.
480+ */
476481 // TODO: Implement path collection
477482 let (path , expr_start ) = collect_idents(None , true , token_list);
478483 switch (path) {
479484 | Some (path ) => CompletableExpressionPath (path, expr_start)
480485 | None => CompletableUnknown
481486 };
482- | [ {token: Parser . LIDENT (str ), start_loc}, {token: Parser . EOL }, ... _ ]
487+ // This is the case of XXXX.X| <- You are actively writing
488+ // TODO: Support test().label on records somehow
489+ | [
490+ {token: Parser . LIDENT (_ ) | Parser . UIDENT (_ ), start_loc},
491+ {token: Parser . EOL },
492+ ... _ ,
493+ ]
483494 when ! hit_eol && start_loc < offset =>
495+ // TODO: Collect the path
484496 if (! in_block) {
485497 CompletableStatement (false );
486498 } else {
@@ -624,10 +636,21 @@ let get_completions_from_context =
624636 (context: completable_context , program: option (Typedtree . typed_program )) => {
625637 // TODO: Consider using the sourcetree to provide some extra env context, thinking type signatures
626638 switch (context) {
627- | CompletableInclude (str ) =>
628- // TODO: Add all paths in Includes
629- // TODO: Add all relative paths
630- [ build_completion("number" , CompletionItemKindFile )]
639+ | CompletableInclude (path , afterPath ) =>
640+ if (afterPath) {
641+ [
642+ // TODO: Implement completion for include Module name, Note: This is going to take some work as the module is not loaded into the env
643+ // We are at from "path" | <- cursor is represented by |
644+ build_completion("include" , CompletionItemKindKeyword ),
645+ ] ;
646+ } else {
647+ [
648+ // TODO: Add all paths in Includes
649+ // TODO: Add all relative paths
650+ // We are at from "|" <- cursor is represented by |
651+ build_completion("number" , CompletionItemKindFile ),
652+ ] ;
653+ }
631654 | CompletableStatement (true ) =>
632655 switch (program) {
633656 | Some ({env}) =>
0 commit comments