Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Code #896

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,10 @@ module Compile = struct
| _ ->
Stats.logHygieneNamedArgValue ~label ~loc;
raise ArgError
[@@raises ArgError]
[@@raises ArgError]
in
functionArg ()
[@@raises ArgError]
[@@raises ArgError]
in
let functionArgsOpt =
try Some (functionDefinition.kind |> List.map getFunctionArg)
Expand Down Expand Up @@ -1320,15 +1320,15 @@ let traverseAst ~valueBindingsTable =
progressFunctionsFromAttributes valueBinding.vb_attributes
with
| None -> (progressFunctions, functionsToAnalyze)
| Some newProgressFunctions -> (
| Some newProgressFunctions ->
( StringSet.union
(StringSet.of_list newProgressFunctions)
progressFunctions,
match valueBinding.vb_pat.pat_desc with
| Tpat_var (id, _) ->
(Ident.name id, valueBinding.vb_expr.exp_loc)
:: functionsToAnalyze
| _ -> functionsToAnalyze )))
| _ -> functionsToAnalyze ))
(StringSet.empty, [])
in
(progressFunctions0, functionsToAnalyze0 |> List.rev)
Expand Down
12 changes: 6 additions & 6 deletions analysis/reanalyze/src/DeadValue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ let collectValueBinding super self (vb : Typedtree.value_binding) =
| _ -> false
in
(if (not exists) && not isFirstClassModule then
(* This is never toplevel currently *)
let isToplevel = oldLastBinding = Location.none in
let sideEffects = SideEffects.checkExpr vb.vb_expr in
name
|> addValueDeclaration ~isToplevel ~loc ~moduleLoc:currentModulePath.loc
~optionalArgs ~path ~sideEffects);
(* This is never toplevel currently *)
let isToplevel = oldLastBinding = Location.none in
let sideEffects = SideEffects.checkExpr vb.vb_expr in
name
|> addValueDeclaration ~isToplevel ~loc
~moduleLoc:currentModulePath.loc ~optionalArgs ~path ~sideEffects);
(match PosHash.find_opt decls loc_start with
| None -> ()
| Some decl ->
Expand Down
54 changes: 27 additions & 27 deletions analysis/reanalyze/src/Exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ module Event = struct
if !Common.Cli.debug then Log_.item "%a@." print ev;
let nestedExceptions = loop Exceptions.empty nestedEvents in
(if Exceptions.isEmpty nestedExceptions (* catch-all *) then
let name =
match nestedEvents with
| {kind = Call {callee}} :: _ -> callee |> Common.Path.toName
| _ -> "expression" |> Name.create
in
Log_.warning ~loc
(Common.ExceptionAnalysis
{
message =
Format.asprintf
"@{<info>%s@} does not raise and is annotated with \
redundant @doesNotRaise"
(name |> Name.toString);
}));
let name =
match nestedEvents with
| {kind = Call {callee}} :: _ -> callee |> Common.Path.toName
| _ -> "expression" |> Name.create
in
Log_.warning ~loc
(Common.ExceptionAnalysis
{
message =
Format.asprintf
"@{<info>%s@} does not raise and is annotated with \
redundant @doesNotRaise"
(name |> Name.toString);
}));
loop exnSet rest
| ({kind = Catches nestedEvents; exceptions} as ev) :: rest ->
if !Common.Cli.debug then Log_.item "%a@." print ev;
Expand Down Expand Up @@ -192,11 +192,11 @@ module Checks = struct
let missingAnnotations = Exceptions.diff raiseSet exceptions in
let redundantAnnotations = Exceptions.diff exceptions raiseSet in
(if not (Exceptions.isEmpty missingAnnotations) then
let description =
Common.ExceptionAnalysisMissing
{exnName; exnTable; raiseSet; missingAnnotations; locFull}
in
Log_.warning ~loc description);
let description =
Common.ExceptionAnalysisMissing
{exnName; exnTable; raiseSet; missingAnnotations; locFull}
in
Log_.warning ~loc description);
if not (Exceptions.isEmpty redundantAnnotations) then
Log_.warning ~loc
(Common.ExceptionAnalysis
Expand Down Expand Up @@ -356,14 +356,14 @@ let traverseAst () =
cases |> iterCases self
| _ -> super.expr self expr |> ignore);
(if isDoesNoRaise then
let nestedEvents = !currentEvents in
currentEvents :=
{
Event.exceptions = Exceptions.empty;
loc;
kind = DoesNotRaise nestedEvents;
}
:: oldEvents);
let nestedEvents = !currentEvents in
currentEvents :=
{
Event.exceptions = Exceptions.empty;
loc;
kind = DoesNotRaise nestedEvents;
}
:: oldEvents);
expr
in
let getExceptionsFromAnnotations attributes =
Expand Down
8 changes: 4 additions & 4 deletions analysis/reanalyze/src/Log_.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ module Loc = struct
pos_cnum = char;
pos_fname =
(let open Filename in
match is_implicit pos.pos_fname with
| _ when !Cli.ci -> basename pos.pos_fname
| true -> concat (Sys.getcwd ()) pos.pos_fname
| false -> pos.pos_fname);
match is_implicit pos.pos_fname with
| _ when !Cli.ci -> basename pos.pos_fname
| true -> concat (Sys.getcwd ()) pos.pos_fname
| false -> pos.pos_fname);
}
in
Location.print_loc ppf
Expand Down
4 changes: 2 additions & 2 deletions analysis/reanalyze/src/Reanalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ let cli () =
let versionAndExit () =
print_endline usage;
exit 0
[@@raises exit]
[@@raises exit]
in
let rec setAll cmtRoot =
RunConfig.all ();
Expand Down Expand Up @@ -216,7 +216,7 @@ let cli () =
if !analysisKindSet = false then setConfig ();
let cmtRoot = !cmtRootRef in
runAnalysisAndReport ~cmtRoot
[@@raises exit]
[@@raises exit]

module RunConfig = RunConfig
module Log_ = Log_
62 changes: 31 additions & 31 deletions analysis/reanalyze/src/WriteDeadAnnotations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ let rec lineToString_ {original; declarations} =
{
original =
(if String.length original >= col && col > 0 then
let original1, original2 =
try
( String.sub original 0 col,
String.sub original col (originalLen - col) )
with Invalid_argument _ -> (original, "")
in
if language = Res && declKind = VariantCase then
if
String.length original2 >= 2
&& (String.sub [@doesNotRaise]) original2 0 2 = "| "
then
original1 ^ "| " ^ annotationStr
^ (String.sub [@doesNotRaise]) original2 2
(String.length original2 - 2)
else if
String.length original2 >= 1
&& (String.sub [@doesNotRaise]) original2 0 1 = "|"
then
original1 ^ "|" ^ annotationStr
^ (String.sub [@doesNotRaise]) original2 1
(String.length original2 - 1)
else original1 ^ "| " ^ annotationStr ^ original2
else original1 ^ annotationStr ^ original2
else
match language = Ml with
| true -> original ^ annotationStr
| false -> annotationStr ^ original);
let original1, original2 =
try
( String.sub original 0 col,
String.sub original col (originalLen - col) )
with Invalid_argument _ -> (original, "")
in
if language = Res && declKind = VariantCase then
if
String.length original2 >= 2
&& (String.sub [@doesNotRaise]) original2 0 2 = "| "
then
original1 ^ "| " ^ annotationStr
^ (String.sub [@doesNotRaise]) original2 2
(String.length original2 - 2)
else if
String.length original2 >= 1
&& (String.sub [@doesNotRaise]) original2 0 1 = "|"
then
original1 ^ "|" ^ annotationStr
^ (String.sub [@doesNotRaise]) original2 1
(String.length original2 - 1)
else original1 ^ "| " ^ annotationStr ^ original2
else original1 ^ annotationStr ^ original2
else
match language = Ml with
| true -> original ^ annotationStr
| false -> annotationStr ^ original);
declarations = nextDeclarations;
}
|> lineToString_
Expand All @@ -91,7 +91,7 @@ let readFile fileName =
let line = {original = input_line channel; declarations = []} in
lines := line :: !lines;
loop ()
[@@raises End_of_file]
[@@raises End_of_file]
in
try loop ()
with End_of_file ->
Expand Down Expand Up @@ -122,9 +122,9 @@ let getLineAnnotation ~decl ~line =
posAnnotation.pos_cnum - posAnnotation.pos_bol + offset )
~text:
(if decl.posAdjustment = FirstVariant then
(* avoid syntax error *)
"| @dead "
else "@dead ")
(* avoid syntax error *)
"| @dead "
else "@dead ")
~action:"Suppress dead code warning"
else
Format.asprintf "@. <-- line %d@. %s" decl.pos.pos_lnum
Expand Down
108 changes: 54 additions & 54 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -697,60 +697,60 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
let attribute (iterator : Ast_iterator.iterator)
((id, payload) : Parsetree.attribute) =
(if String.length id.txt >= 4 && String.sub id.txt 0 4 = "res." then
(* skip: internal parser attribute *) ()
else if id.loc.loc_ghost then ()
else if id.loc |> Loc.hasPos ~pos:posBeforeCursor then
let posStart, posEnd = Loc.range id.loc in
match
(Pos.positionToOffset text posStart, Pos.positionToOffset text posEnd)
with
| Some offsetStart, Some offsetEnd ->
(* Can't trust the parser's location
E.g. @foo. let x... gives as label @foo.let *)
let label =
let rawLabel =
String.sub text offsetStart (offsetEnd - offsetStart)
in
let ( ++ ) x y =
match (x, y) with
| Some i1, Some i2 -> Some (min i1 i2)
| Some _, None -> x
| None, _ -> y
in
let label =
match
String.index_opt rawLabel ' '
++ String.index_opt rawLabel '\t'
++ String.index_opt rawLabel '\r'
++ String.index_opt rawLabel '\n'
with
| None -> rawLabel
| Some i -> String.sub rawLabel 0 i
in
if label <> "" && label.[0] = '@' then
String.sub label 1 (String.length label - 1)
else label
in
found := true;
if debug then
Printf.printf "Attribute id:%s:%s label:%s\n" id.txt
(Loc.toString id.loc) label;
setResult (Completable.Cdecorator label)
| _ -> ()
else if id.txt = "module" then
(match payload with
| PStr
[
{
pstr_desc =
Pstr_eval
( {pexp_loc; pexp_desc = Pexp_constant (Pconst_string (s, _))},
_ );
};
]
when locHasCursor pexp_loc ->
setResult (Completable.CdecoratorPayload (Module s))
| _ -> ()));
(* skip: internal parser attribute *) ()
else if id.loc.loc_ghost then ()
else if id.loc |> Loc.hasPos ~pos:posBeforeCursor then
let posStart, posEnd = Loc.range id.loc in
match
(Pos.positionToOffset text posStart, Pos.positionToOffset text posEnd)
with
| Some offsetStart, Some offsetEnd ->
(* Can't trust the parser's location
E.g. @foo. let x... gives as label @foo.let *)
let label =
let rawLabel =
String.sub text offsetStart (offsetEnd - offsetStart)
in
let ( ++ ) x y =
match (x, y) with
| Some i1, Some i2 -> Some (min i1 i2)
| Some _, None -> x
| None, _ -> y
in
let label =
match
String.index_opt rawLabel ' '
++ String.index_opt rawLabel '\t'
++ String.index_opt rawLabel '\r'
++ String.index_opt rawLabel '\n'
with
| None -> rawLabel
| Some i -> String.sub rawLabel 0 i
in
if label <> "" && label.[0] = '@' then
String.sub label 1 (String.length label - 1)
else label
in
found := true;
if debug then
Printf.printf "Attribute id:%s:%s label:%s\n" id.txt
(Loc.toString id.loc) label;
setResult (Completable.Cdecorator label)
| _ -> ()
else if id.txt = "module" then
match payload with
| PStr
[
{
pstr_desc =
Pstr_eval
( {pexp_loc; pexp_desc = Pexp_constant (Pconst_string (s, _))},
_ );
};
]
when locHasCursor pexp_loc ->
setResult (Completable.CdecoratorPayload (Module s))
| _ -> ());
Ast_iterator.default_iterator.attribute iterator (id, payload)
in
let rec iterateFnArguments ~args ~iterator ~isPipe
Expand Down
18 changes: 9 additions & 9 deletions analysis/src/DocumentSymbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ let command ~path =
in

(if Filename.check_suffix path ".res" then
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore
else
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
let {Res_driver.parsetree = signature} = parser ~filename:path in
iterator.signature iterator signature |> ignore);
let parser =
Res_driver.parsingEngine.parseImplementation ~forPrinter:false
in
let {Res_driver.parsetree = structure} = parser ~filename:path in
iterator.structure iterator structure |> ignore
else
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
let {Res_driver.parsetree = signature} = parser ~filename:path in
iterator.signature iterator signature |> ignore);
let isInside
({
range =
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/Files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let relpath base path =
let baselen = String.length base in
let rest = String.sub path baselen (String.length path - baselen) in
(if rest <> "" && rest.[0] = Filename.dir_sep.[0] then sliceToEnd rest 1
else rest)
else rest)
|> removeExtraDots
else
let rec loop bp pp =
Expand Down
Loading
Loading