-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Track start and end column for symbols #304
Closed
Closed
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b1ed773
Add start_column and end_column to symbols table
crbelaus 0c494e5
Record start and end column when saving symbols
crbelaus 75737b0
Use start and end column when querying symbols
crbelaus cc660fd
Remove unwanted 'dbg' call
crbelaus f5fbd49
Try to infer defmodule/defstruct columns from references
crbelaus d6085f4
ci: add 1.16.0-rc.0
mhanberg c51dcdc
Merge branch 'main' into track-symbol-columns
mhanberg 8752e19
Merge branch 'main' into track-symbol-columns
mhanberg 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,10 +93,10 @@ defmodule NextLS.DB do | |
__query__( | ||
{conn, s.logger}, | ||
~Q""" | ||
INSERT INTO symbols (module, file, type, name, line, 'column', source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?); | ||
INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?); | ||
""", | ||
[mod, file, "defmodule", mod, module_line, 1, source] | ||
[mod, file, "defmodule", mod, module_line, 1, 1, source] | ||
) | ||
|
||
if struct do | ||
|
@@ -105,32 +105,36 @@ defmodule NextLS.DB do | |
__query__( | ||
{conn, s.logger}, | ||
~Q""" | ||
INSERT INTO symbols (module, file, type, name, line, 'column', source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?); | ||
INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?); | ||
""", | ||
[mod, file, "defstruct", "%#{Macro.to_string(mod)}{}", meta[:line], 1, source] | ||
[mod, file, "defstruct", "%#{Macro.to_string(mod)}{}", meta[:line], 1, 1, source] | ||
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. Same as above. |
||
) | ||
end | ||
|
||
for {name, {:v1, type, _meta, clauses}} <- defs, {meta, _, _, _} <- clauses do | ||
# Elixir versions older than 1.16 did not provide column metadata | ||
column_start = meta[:column] || 1 | ||
name = to_string(name) | ||
|
||
__query__( | ||
{conn, s.logger}, | ||
~Q""" | ||
INSERT INTO symbols (module, file, type, name, line, 'column', source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?); | ||
INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?); | ||
""", | ||
[mod, file, type, name, meta[:line], meta[:column] || 1, source] | ||
[mod, file, type, name, meta[:line], column_start, column_start + String.length(name), source] | ||
) | ||
end | ||
|
||
for {type, name, line, column} <- symbols do | ||
__query__( | ||
{conn, s.logger}, | ||
~Q""" | ||
INSERT INTO symbols (module, file, type, name, line, 'column', source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?); | ||
INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?); | ||
""", | ||
[mod, file, type, name, line, column, source] | ||
[mod, file, type, name, line, column, column + String.length(name), source] | ||
) | ||
end | ||
|
||
|
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.
I am not sure if it would be better to just not store the
start_column
andend_column
in this case. The current information is not accurate and it may be more confusing than not having it.This would also make it easier to query for symbols as we would just return the results in which the column matches or there is no column. Currently we have to discard
defmodule
anddefstruct
manually when querying.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.
So, for defstruct, I believe we can query the reference table to get the start/end column information. i think that since the module is now compiled, all of the references in it should already have been traced.
For defmodule, it seems like only calls to
defmodule
that are inside another module are traced (not sure if that is a bug or an implementation detail), but you can most likely use it for column info for sub moduled, modules, and then if that doesn't exist, just assume its normal and its at column 1 (or 0, i can't remember how we store it)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've just added a new commit that does this and it seems to work fine both for
defstruct
and nesteddefmodule
declarations. For top leveldefmodule
declarations we don't have this information and are storing bothstart_column
andend_columns
as 1.I tested it by adding the following module and confirming that every
defstruct
and the nesteddefmodule
has the right columns.I was thinking that we could do a little bit better as we know that the start column is 11 ("defmodule " has 10 characters) and we can add the module name length to get the end column. Not sure about this though as it seems too "clever" and fragile.