|
| 1 | +open SharedTypes |
| 2 | + |
| 3 | +let resolveOpens = CompletionBackEnd.resolveOpens |
| 4 | +let getOpens = CompletionBackEnd.getOpens |
| 5 | + |
| 6 | +let findFields ~env ~package ~hint typ = |
| 7 | + match TypeUtils.extractRecordType ~env ~package typ with |
| 8 | + | None -> [] |
| 9 | + | Some (_recordEnv, fields, decl) -> |
| 10 | + fields |
| 11 | + |> DotCompletionUtils.filterRecordFields ~env ~prefix:hint ~exact:false |
| 12 | + ~recordAsString:(decl.item.decl |> Shared.declToString decl.name.txt) |
| 13 | + |
| 14 | +let processCompletable ~debug ~full ~scope ~env ~pos |
| 15 | + (completable : CompletableRevamped.t) = |
| 16 | + let package = full.package in |
| 17 | + let rawOpens = Scope.getRawOpens scope in |
| 18 | + let opens = getOpens ~debug ~rawOpens ~package ~env in |
| 19 | + let allFiles = allFilesInPackage package in |
| 20 | + |
| 21 | + ignore pos; |
| 22 | + ignore opens; |
| 23 | + ignore allFiles; |
| 24 | + |
| 25 | + match completable with |
| 26 | + | Cexpression {kind; typeLoc} -> ( |
| 27 | + match TypeUtils.findTypeViaLoc typeLoc ~full ~debug with |
| 28 | + | None -> [] |
| 29 | + | Some typ -> ( |
| 30 | + match kind with |
| 31 | + | Field {hint} -> findFields ~env ~package ~hint typ)) |
| 32 | + | Cnone -> [] |
| 33 | + | CextensionNode _ -> [] |
| 34 | + | Cdecorator prefix -> |
| 35 | + let mkDecorator (name, docstring, maybeInsertText) = |
| 36 | + { |
| 37 | + (Completion.create name ~synthetic:true ~includesSnippets:true |
| 38 | + ~kind:(Label "") ~env ?insertText:maybeInsertText) |
| 39 | + with |
| 40 | + docstring; |
| 41 | + } |
| 42 | + in |
| 43 | + let isTopLevel = String.starts_with ~prefix:"@" prefix in |
| 44 | + let prefix = |
| 45 | + if isTopLevel then String.sub prefix 1 (String.length prefix - 1) |
| 46 | + else prefix |
| 47 | + in |
| 48 | + let decorators = |
| 49 | + if isTopLevel then CompletionDecorators.toplevel |
| 50 | + else CompletionDecorators.local |
| 51 | + in |
| 52 | + decorators |
| 53 | + |> List.filter (fun (decorator, _, _) -> Utils.startsWith decorator prefix) |
| 54 | + |> List.map (fun (decorator, maybeInsertText, doc) -> |
| 55 | + let parts = String.split_on_char '.' prefix in |
| 56 | + let len = String.length prefix in |
| 57 | + let dec2 = |
| 58 | + if List.length parts > 1 then |
| 59 | + String.sub decorator len (String.length decorator - len) |
| 60 | + else decorator |
| 61 | + in |
| 62 | + (dec2, doc, maybeInsertText)) |
| 63 | + |> List.map mkDecorator |
| 64 | + | CdecoratorPayload _ -> [] |
0 commit comments