-
Notifications
You must be signed in to change notification settings - Fork 59
Fix references to file modules #254
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
Fix references to file modules #254
Conversation
This pr adds support for global references to a module. // A.res
let a = 2 // B.res
let x = A.a // C.res
let x = A.a requesting refrence on |
There's also this confusing thing that the first line let x = 12 is considered as a reference to So basically 2 things to be solved in user experience. |
Will fix that
Do you think that's bad experience? for me it's like referencing to let binding when i get references on the usage site let x = 2
let b = x if i get refrence on second x, it includes the first let binding which declares x. |
This module reference is different. We want a reference to a module, we get the first line of a file. The user will look at the first line, and might think: how did I get here? That first line has nothing to do with the original query, except it happens to be in the file that the query is about. |
Yeah your argument is valid. |
File rename demo recording.mp4 |
server/src/server.ts
Outdated
changes[uri].push(textEdit); | ||
if (utils.isRangeTopOfFile(range)) { | ||
let filePath = fileURLToPath(uri); | ||
let newFilePath = `${path.dirname(filePath)}/${params.newName}${path.extname(filePath)}`; |
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.
what about Windows paths?
analysis/src/References.ml
Outdated
| Some paths -> ( | ||
let moduleSrcToRef src = (Uri2.fromPath src, [Utils.topLoc src]) in | ||
match paths with | ||
| Impl (_, None) -> [] |
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.
How about move this extraction of source files to SharedTypes
alongside getSrc
.
So that it returns a list of source files.
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 is great, thanks a lot.
I've added a few comments.
In addition, how about adapting the test files so they cover all cases, including implementation and interface files, as well as references from another file than the current one.
thank you i will address them. |
I think eventually it will have to move, as e.g. the |
I will move if it's okay. another thing have to be fixed. looks like there's a problem when the project has |
Great go ahead with moving. |
@amiralies meanwhile I've done some refactoring relevant to a couple of lines of this diff: Specifically, type I can merge and this gets rebased, or it can be done later. |
Maybe you can merge your branch then I will update my branch/PR |
Merged |
ed9748c
to
f15a838
Compare
@amiralies a couple of next steps that fix build and clean up after rebase: Feel free to incorporate and continue. Or I'm also happy to continue if you prefer. |
I will merge your branch on mine, and continue the work here if it's okay. |
Perfect |
Windows tests are failing, I think because the order in which files are processed is nondeterministic. And can become platform-dependent. |
match References.locItemForPos ~full pos with | ||
| None -> Protocol.null | ||
| Some locItem -> | ||
let allReferences = References.allReferencesForLocItem ~full locItem in |
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 list I think can be non-deterministic.
Some fixed order should be chosen (e.g. by sorting the results on Uri then loc).
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.
It might be enough to make fileReferences
inside extra
in SharedTypes.ml
store a set of locations instead of a list.
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.
I will check what's going wrong on a windows setup.
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.
Seems like there was an issue checking for interface file on windows
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.
Great thanks. I've also looked at removing some nondeterminism:
#263
Which I might add later on. To make debugging across platforms easier.
Works to be done aside from issue on windows:
|
I think it's ready for review ! |
let dir = Filename.dirname path in | ||
let ext = Filename.extension path in | ||
let sep = Filename.dir_sep in | ||
let newPath = dir ^ sep ^ newName ^ ext in |
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.
Better use Filename.concat
instead of string concat with sep
.
let newUri = Uri2.fromPath newPath in | ||
Protocol. | ||
{ | ||
kind = `rename; |
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.
Nit: I think it's easier to expose a constructor function in the protocol that only takes 2 parameters: oldUri
and newUri
so the type of kind does not leak here.
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.
Actually, I would just remove kind
and use in the printing function only.
@@ -18,6 +18,20 @@ type location = {uri : string; range : range} | |||
|
|||
type documentSymbolItem = {name : string; kind : int; location : location} | |||
|
|||
type renameFile = {kind : [`rename]; oldUri : string; newUri : string} |
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.
Suggestion: remove kind
.
"oldUri": "%s", | ||
"newUri": "%s" | ||
}|} | ||
(match rf.kind with `rename -> "rename") |
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 can go once field kind
is removed, but the printing of "rename" stays.
@@ -7,6 +7,12 @@ let topLoc fname = | |||
loc_ghost = false; | |||
} | |||
|
|||
let isTopLoc (loc : Warnings.loc) = |
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.
It might be possible to clean this up further, but looks OK for now.
Indeed, it looks great! |
Thanks, I was going to bed. I see you already fixed them |
No description provided.