Skip to content

Commit 090c6fb

Browse files
committed
Refactor return from getFullFromCmt.
1 parent 4de18d5 commit 090c6fb

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

analysis/src/Commands.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ let dump files =
2727
let result =
2828
match ProcessCmt.getFullFromCmt ~uri with
2929
| None -> "[]"
30-
| Some (package, {file; extra}) ->
31-
dumpLocations ~package ~file ~extra
30+
| Some {package; file; extra} -> dumpLocations ~package ~file ~extra
3231
in
3332
print_endline result)
3433

@@ -37,10 +36,9 @@ let completion ~path ~line ~col ~currentFile =
3736
let result =
3837
match ProcessCmt.getFullFromCmt ~uri with
3938
| None -> "[]"
40-
| Some (package, full) ->
39+
| Some full ->
4140
let maybeText = Files.readFile currentFile in
42-
NewCompletions.computeCompletions ~full ~maybeText ~package
43-
~pos:(line, col)
41+
NewCompletions.computeCompletions ~full ~maybeText ~pos:(line, col)
4442
|> List.map Protocol.stringifyCompletionItem
4543
|> Protocol.array
4644
in
@@ -51,7 +49,7 @@ let hover ~path ~line ~col =
5149
let result =
5250
match ProcessCmt.getFullFromCmt ~uri with
5351
| None -> Protocol.null
54-
| Some (package, {file; extra}) -> (
52+
| Some {package; file; extra} -> (
5553
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
5654
match References.locItemForPos ~extra pos with
5755
| None -> Protocol.null
@@ -89,7 +87,7 @@ let definition ~path ~line ~col =
8987
let result =
9088
match ProcessCmt.getFullFromCmt ~uri with
9189
| None -> Protocol.null
92-
| Some (package, {file; extra}) -> (
90+
| Some {package; file; extra} -> (
9391
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
9492

9593
match References.locItemForPos ~extra pos with
@@ -126,7 +124,7 @@ let references ~path ~line ~col =
126124
let result =
127125
match ProcessCmt.getFullFromCmt ~uri with
128126
| None -> Protocol.null
129-
| Some (package, {file; extra}) -> (
127+
| Some {package; file; extra} -> (
130128
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
131129
match References.locItemForPos ~extra pos with
132130
| None -> Protocol.null
@@ -154,7 +152,7 @@ let references ~path ~line ~col =
154152

155153
let documentSymbol ~path =
156154
let uri = Uri2.fromLocalPath path in
157-
match ProcessCmt.fileForUri uri with
155+
match ProcessCmt.getFullFromCmt ~uri with
158156
| None -> print_endline Protocol.null
159157
| Some {file} ->
160158
let open SharedTypes in

analysis/src/NewCompletions.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ let processCompletable ~findItems ~package ~rawOpens
523523
in
524524
let removePackageOpens modulePath =
525525
match modulePath with
526-
| toplevel :: rest when package.opens |> List.mem toplevel ->
527-
rest
526+
| toplevel :: rest when package.opens |> List.mem toplevel -> rest
528527
| _ -> modulePath
529528
in
530529
let rec removeRawOpen rawOpen modulePath =
@@ -637,7 +636,8 @@ let processCompletable ~findItems ~package ~rawOpens
637636
|> List.filter (fun (name, _t) -> Utils.startsWith name prefix)
638637
|> List.map mkLabel
639638

640-
let computeCompletions ~full ~maybeText ~package ~pos =
639+
let computeCompletions ~full ~maybeText ~pos =
640+
let package = full.package in
641641
match maybeText with
642642
| None -> []
643643
| Some text -> (
@@ -648,9 +648,7 @@ let computeCompletions ~full ~maybeText ~package ~pos =
648648
| None -> []
649649
| Some completable ->
650650
let rawOpens = PartialParser.findOpens text offset in
651-
let allModules =
652-
package.localModules @ package.dependencyModules
653-
in
651+
let allModules = package.localModules @ package.dependencyModules in
654652
let findItems ~exact parts =
655653
let items =
656654
getItems ~full ~package ~rawOpens ~allModules ~pos ~parts

analysis/src/ProcessCmt.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,16 +1173,11 @@ let getFullFromCmt ~uri =
11731173
| Ok full ->
11741174
Hashtbl.replace package.interModuleDependencies moduleName
11751175
(SharedTypes.hashList full.extra.externalReferences |> List.map fst);
1176-
Some (package, full))
1176+
Some full)
11771177
| None ->
11781178
prerr_endline ("can't find module " ^ moduleName);
11791179
None)
11801180

1181-
let fileForUri uri =
1182-
match getFullFromCmt ~uri with
1183-
| None -> None
1184-
| Some (_package, full) -> Some full
1185-
11861181
let extraForModule ~package modname =
11871182
if Hashtbl.mem package.pathsForModule modname then
11881183
let paths = Hashtbl.find package.pathsForModule modname in

analysis/src/References.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ let alternateDeclared ~file ~package declared tip =
169169
let intfUri = Uri2.fromPath intf in
170170
let implUri = Uri2.fromPath impl in
171171
if intfUri = file.uri then
172-
match ProcessCmt.fileForUri implUri with
172+
match ProcessCmt.getFullFromCmt ~uri:implUri with
173173
| None -> None
174174
| Some {file; extra} -> (
175175
match
@@ -179,7 +179,7 @@ let alternateDeclared ~file ~package declared tip =
179179
| None -> None
180180
| Some declared -> Some (file, extra, declared))
181181
else
182-
match ProcessCmt.fileForUri intfUri with
182+
match ProcessCmt.getFullFromCmt ~uri:intfUri with
183183
| None -> None
184184
| Some {file; extra} -> (
185185
match
@@ -414,7 +414,7 @@ let forLocalStamp ~package ~file ~extra stamp tip =
414414
| Some file -> (
415415
match ProcessCmt.extraForModule ~package name with
416416
| None -> None
417-
| Some (_, {extra}) -> (
417+
| Some {extra} -> (
418418
match
419419
Hashtbl.find_opt extra.externalReferences
420420
thisModuleName
@@ -459,7 +459,7 @@ let allReferencesForLocItem ~package ~file ~extra locItem =
459459
match ProcessCmt.exportedForTip ~env name tip with
460460
| None -> []
461461
| Some stamp -> (
462-
match ProcessCmt.fileForUri env.qFile.uri with
462+
match ProcessCmt.getFullFromCmt ~uri:env.qFile.uri with
463463
| None -> []
464464
| Some {file; extra} ->
465465
maybeLog

0 commit comments

Comments
 (0)