-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #840 from ejgallego/codeAction
Code Actions
- Loading branch information
Showing
26 changed files
with
371 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
let point_lt { Lang.Point.line = l1; Lang.Point.character = c1; offset = _ } | ||
{ Lang.Point.line = l2; Lang.Point.character = c2; offset = _ } = | ||
l1 < l2 || (l1 = l2 && c1 < c2) | ||
|
||
let point_gt { Lang.Point.line = l1; Lang.Point.character = c1; offset = _ } | ||
{ Lang.Point.line = l2; Lang.Point.character = c2; offset = _ } = | ||
l1 > l2 || (l1 = l2 && c1 > c2) | ||
|
||
(* To move to doc.ml *) | ||
let filter_map_range ~range ~nodes ~f = | ||
let rec aux (nodes : Fleche.Doc.Node.t list) acc = | ||
match nodes with | ||
| [] -> List.rev acc | ||
| node :: nodes -> ( | ||
let open Lang.Range in | ||
let nrange = node.range in | ||
if point_lt nrange.end_ range.start then aux nodes acc | ||
else if point_gt nrange.start range.end_ then List.rev acc | ||
else | ||
(* Node in scope *) | ||
match f node with | ||
| Some res -> aux nodes (res :: acc) | ||
| None -> aux nodes acc) | ||
in | ||
aux nodes [] | ||
|
||
(* util *) | ||
let filter_map_cut f l = | ||
match List.filter_map f l with | ||
| [] -> None | ||
| res -> Some res | ||
|
||
(* Return list of pairs of diags, qf *) | ||
let get_qf (d : Lang.Diagnostic.t) : _ option = | ||
Option.bind d.data (function | ||
| { Lang.Diagnostic.Data.quickFix = Some qf; _ } -> Some (d, qf) | ||
| _ -> None) | ||
|
||
let get_qfs ~range (doc : Fleche.Doc.t) = | ||
let f { Fleche.Doc.Node.diags; _ } = filter_map_cut get_qf diags in | ||
filter_map_range ~range ~nodes:doc.nodes ~f |> List.concat | ||
|
||
let request ~range ~token:_ ~(doc : Fleche.Doc.t) = | ||
let kind = Some "quickfix" in | ||
let isPreferred = Some true in | ||
let qf = get_qfs ~range doc in | ||
let bf (d, qf) = | ||
List.map | ||
(fun { Lang.Qf.range; newText } -> | ||
let oldText = | ||
Fleche.Contents.extract_raw ~contents:doc.contents ~range | ||
in | ||
let title = Format.asprintf "Replace `%s` by `%s`" oldText newText in | ||
let diagnostics = [ d ] in | ||
let qf = [ Lsp.Workspace.TextEdit.{ range; newText } ] in | ||
let changes = [ (doc.uri, qf) ] in | ||
let edit = Some Lsp.Workspace.WorkspaceEdit.{ changes } in | ||
Lsp.Core.CodeAction.{ title; kind; diagnostics; isPreferred; edit }) | ||
qf | ||
in | ||
List.concat_map bf qf | ||
|
||
let request ~range ~token ~(doc : Fleche.Doc.t) = | ||
let res = request ~range ~token ~doc in | ||
Ok (`List (List.map Lsp.Core.CodeAction.to_yojson res)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val request : range:Lang.Range.t -> Request.document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(* Test for Coq's QF for Coq to Stdlib PRs *) | ||
|
||
Require Import Coq.ssr.ssrbool. | ||
From Coq Require Import ssreflect ssrbool. | ||
|
||
(* Note: this tests the two different lookup modes *) | ||
About Coq.Init.Nat.add. | ||
Check Coq.Init.Nat.add. | ||
|
||
(* Example codeAction, from Coq's test suite *) | ||
|
||
Module M. Definition y := 4. End M. | ||
Import M. | ||
|
||
#[deprecated(use=y)] | ||
Definition x := 3. | ||
|
||
Module N. Definition y := 5. End N. | ||
Import N. | ||
|
||
Definition d1 := x = 3. | ||
|
||
Module M1. | ||
Notation w := x. | ||
End M1. | ||
Import M1. | ||
|
||
#[deprecated(use=w)] | ||
Notation v := 3. | ||
|
||
Module M2. | ||
Notation w := 5. | ||
End M2. | ||
Import M2. | ||
|
||
Definition d2 := v = 3. | ||
|
||
Fail #[deprecated(use=w)] | ||
Notation "a +++ b" := (a + b) (at level 2). | ||
|
||
Fail #[deprecated(use=nonexisting)] | ||
Definition y := 2. | ||
|
||
(***********************************************) | ||
Module A. | ||
End B. | ||
|
||
(***********************************************) | ||
Require Import Extraction. | ||
|
||
Module nat. End nat. | ||
|
||
Extraction nat. | ||
|
Oops, something went wrong.