-
Notifications
You must be signed in to change notification settings - Fork 69
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
feat: jump to definition proof of concept #911
Draft
rtetley
wants to merge
2
commits into
main
Choose a base branch
from
jump-to-def
base: main
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.
+92
−8
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -658,6 +658,69 @@ let hover st pos = | |||||||||
hover_of_sentence st loc pattern (Document.find_next_qed st.document loc) | ||||||||||
| _ -> None | ||||||||||
|
||||||||||
(* match loc.Loc.fname with | ||||||||||
| Loc.ToplevelInput | InFile { dirpath = None } -> Loc.pr loc | ||||||||||
| InFile { dirpath = Some dp } -> | ||||||||||
let f = Loadpath.locate_absolute_library @@ Libnames.dirpath_of_string dp in | ||||||||||
let f = match f with | ||||||||||
| Ok f -> | ||||||||||
let f = Filename.remove_extension f ^ ".v" in | ||||||||||
if Sys.file_exists f | ||||||||||
then str "File " ++ qstring f | ||||||||||
else str "Library " ++ qstring dp | ||||||||||
| Error _ -> str "Library " ++ qstring dp | ||||||||||
in | ||||||||||
(f ++ | ||||||||||
str", line " ++ int loc.line_nb ++ str", characters " ++ | ||||||||||
int (loc.bp-loc.bol_pos) ++ str"-" ++ int (loc.ep-loc.bol_pos)) *) | ||||||||||
|
||||||||||
let jump_to_definition st pos = | ||||||||||
let raw_doc = Document.raw_document st.document in | ||||||||||
let loc = RawDocument.loc_of_position raw_doc pos in | ||||||||||
let opattern = RawDocument.word_at_position raw_doc pos in | ||||||||||
match opattern with | ||||||||||
| None -> log "jumpToDef: no word found at cursor"; None | ||||||||||
| Some pattern -> | ||||||||||
log ("jumpToDef: found word at cursor: \"" ^ pattern ^ "\""); | ||||||||||
match st.observe_id with | ||||||||||
| None -> log "jumpToDef in continuous mode currently not supported"; None | ||||||||||
| Some Top -> log "jumpToDef with no context"; None | ||||||||||
| Some (Id id) -> | ||||||||||
match Document.get_sentence st.document id with | ||||||||||
| None -> log "jumpToDef: observe_id does not exist"; None | ||||||||||
| Some { stop } -> | ||||||||||
let o_pos = RawDocument.position_of_loc raw_doc stop in | ||||||||||
match get_context st o_pos with | ||||||||||
| None -> log "No context found"; None | ||||||||||
| Some _ -> | ||||||||||
match parse_entry st loc (Pcoq.Prim.smart_global) pattern with | ||||||||||
| { v = AN qid } -> | ||||||||||
begin match Nametab.locate qid with | ||||||||||
| ConstRef x -> begin match Declare.get_loc x with | ||||||||||
Comment on lines
+698
to
+699
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. this will need updating as I moved get_loc and made it apply to more than constants
Suggested change
should work |
||||||||||
| None -> None | ||||||||||
| Some loc -> | ||||||||||
begin match loc.Loc.fname with | ||||||||||
| Loc.ToplevelInput | InFile { dirpath = None } -> None | ||||||||||
| InFile { dirpath = Some dp } -> | ||||||||||
let f = Loadpath.locate_absolute_library @@ Libnames.dirpath_of_string dp in | ||||||||||
begin match f with | ||||||||||
| Ok f -> | ||||||||||
let f = Filename.remove_extension f ^ ".v" in | ||||||||||
(if Sys.file_exists f then | ||||||||||
let range = RawDocument.range_of_loc raw_doc loc in | ||||||||||
Some (range, f) | ||||||||||
else | ||||||||||
None | ||||||||||
) | ||||||||||
| Error _ -> None | ||||||||||
end | ||||||||||
end | ||||||||||
end | ||||||||||
| _ -> None | ||||||||||
end | ||||||||||
| _ -> None | ||||||||||
|
||||||||||
|
||||||||||
let check st pos ~pattern = | ||||||||||
let loc = RawDocument.loc_of_position (Document.raw_document st.document) pos in | ||||||||||
match get_context st pos with | ||||||||||
|
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.
since you're only using the
AN
case of smart_global