-
Notifications
You must be signed in to change notification settings - Fork 448
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
PoC: emit code actions from the compiler that the editor tooling can use #7040
Draft
zth
wants to merge
6
commits into
master
Choose a base branch
from
code-actions-driven-by-compiler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e91a63b
PoC: emit code actions from the compiler that the editor tooling can use
zth 46d0330
small cleanup
zth c89af81
its an array
zth 8415e75
automatic code action for spellcheck 'did you mean' text
zth edacb5b
add 'wrap in Some()' code action
zth 03dcd2f
add tests for editor enhancements mode
zth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -112,3 +112,5 @@ val as_pp : bool ref | |
val self_stack : string Stack.t | ||
|
||
val modules : bool ref | ||
|
||
val code_action_data : bool ref |
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,61 @@ | ||
type code_action_type = WrapWith of {left: string; right: string} | ||
type code_action_style = Regular | QuickFix | ||
type code_action = { | ||
style: code_action_style; | ||
type_: code_action_type; | ||
title: string; | ||
} | ||
|
||
let code_action_data = ref [] | ||
let add_code_action (data : code_action) = | ||
code_action_data := data :: !code_action_data | ||
let get_code_action_data () = !code_action_data | ||
|
||
let escape text = | ||
let ln = String.length text in | ||
let buf = Buffer.create ln in | ||
let rec loop i = | ||
if i < ln then ( | ||
(match text.[i] with | ||
| '\012' -> Buffer.add_string buf "\\f" | ||
| '\\' -> Buffer.add_string buf "\\\\" | ||
| '"' -> Buffer.add_string buf "\\\"" | ||
| '\n' -> Buffer.add_string buf "\\n" | ||
| '\b' -> Buffer.add_string buf "\\b" | ||
| '\r' -> Buffer.add_string buf "\\r" | ||
| '\t' -> Buffer.add_string buf "\\t" | ||
| c -> Buffer.add_char buf c); | ||
loop (i + 1)) | ||
in | ||
loop 0; | ||
Buffer.contents buf | ||
|
||
let loc_to_json loc = | ||
Printf.sprintf | ||
"{\"start\": {\"line\": %s, \"col\": %s},\"end\": {\"line\": %s, \"col\": \ | ||
%s}}" | ||
(loc.Location.loc_start.pos_lnum |> string_of_int) | ||
(loc.loc_start.pos_cnum |> string_of_int) | ||
(loc.loc_end.pos_lnum |> string_of_int) | ||
(loc.loc_end.pos_cnum |> string_of_int) | ||
|
||
let code_action_type_to_json = function | ||
| WrapWith {left; right} -> | ||
Printf.sprintf "\"type\": \"wrapWith\", \"wrapLeft\": \"%s\", \"wrapRight\": \"%s\"" | ||
(escape left) (escape right) | ||
|
||
let emit_code_actions_data loc ppf = | ||
match !code_action_data with | ||
| [] -> () | ||
| code_actions -> | ||
Format.fprintf ppf "@\n=== CODE ACTIONS ===@\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build system and editor tooling can extract this line + the rest of the content whenever it encounters it, and extract the code actions from there. And show the actual error in the terminal and in the editor without this text. |
||
code_actions | ||
|> List.iter (fun data -> | ||
Format.fprintf ppf | ||
"{\"title\": \"%s\", \"kind\": \"%s\" \"loc\": %s, %s}" | ||
(escape data.title) | ||
(match data.style with | ||
| Regular -> "regular" | ||
| QuickFix -> "quickfix") | ||
(loc_to_json loc) | ||
(code_action_type_to_json data.type_)) |
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,12 @@ | ||
type code_action_type = WrapWith of {left: string; right: string} | ||
type code_action_style = Regular | QuickFix | ||
type code_action = { | ||
style: code_action_style; | ||
type_: code_action_type; | ||
title: string; | ||
} | ||
|
||
val add_code_action: code_action -> unit | ||
val get_code_action_data: unit -> code_action list | ||
|
||
val emit_code_actions_data: Location.t -> Format.formatter -> unit |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't actually used yet, but we can probably have a
bsc
config like this.