-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Generalizing SourceFile - adding line/column offsets etc #190
Comments
The main purpose of Related, we might need |
Couple of points from the LS side of things:
struct Position
line::Int
column::Int
end
struct SourceSnippet
code::String
first_position::Position
line_starts::Vector{Int}
end
# LS would actually not use this
struct SourceFile
code::SourceSnippet
filename::Union{Nothing,String}
end
# LS would use this instead
struct TextDocument
code::SourceSnippet
uri::URI
version::Int
end
struct NotebookCell
code::SourceSnippet
other fields...
end I hope this doesn't derail the original issue too much, I guess my main point is that just adding a first line and nothing about column seems weird to me :) |
Thanks David this is very useful context. I haven't been able to look at LS integration at all yet or what would be required for incremental parsing.
Agreed. For now I'm happy with merging #191 to get what Tim needs, but we can go with something more complete in the future. Related to source abstractions, the internal |
Let's keep this issue open to discuss that |
lineno
to SourceFile
?When parsing source code fragments incrementally with * `Meta.parse(str, index)` or * `parsestmt(str, index)` we must avoid scanning the rest of `str` for line numbers for efficiency. In this mode, the user is expected to provide `first_line` to "manually" specify which line number we're counting from. Admittedly this is a bit clunky and should be integrated better with SourceFile (which should also be renamed - see issue #190) but for now seems to be the most consistent way to approach things here.
When parsing source code fragments incrementally with * `Meta.parse(str, index)` or * `parsestmt(str, index)` we must avoid scanning the rest of `str` for line numbers for efficiency. In this mode, the user is expected to provide `first_line` to "manually" specify which line number we're counting from. Admittedly this is a bit clunky and should be integrated better with SourceFile (which should also be renamed - see issue #190) but for now seems to be the most consistent way to approach things here.
When parsing source code fragments incrementally with * `Meta.parse(str, index)` or * `parsestmt(str, index)` we must avoid scanning the rest of `str` for line numbers for efficiency. In this mode, the user is expected to provide `first_line` to "manually" specify which line number we're counting from. Admittedly this is a bit clunky and should be integrated better with SourceFile (which should also be renamed - see issue #190) but for now seems to be the most consistent way to approach things here. As part of the refactoring here, switch over to using `Vector{UInt8}` for literal parsing which makes parsing to `ParseStream` and `GreenNode` around 10% faster.
JuliaDebug/Cthulhu.jl#345 uses JuliaSyntax to represent source code with expression boundaries mapped to character positions within the source text. In that application, CodeTracking is used to extract source-text for specific methods which may be partway into a file.
Question: for "snippets" like these, should the starting line number
lineno
be added as a new field toSourceFile
? Or do you need it to represent "a whole file"? If so, then adding it as a field seems incorrect, since of course a whole file will start at line 1. The other issue is whether functions likesource_line
should return the offset line or the line index; currently the two are the same. It's for reasons like these that I didn't want to add it without thinking about the consequences.The text was updated successfully, but these errors were encountered: