-
-
Notifications
You must be signed in to change notification settings - Fork 370
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
Improve parsing of import suggestions extending multiple multiline imports (fixes #4175) #4177
Conversation
#if MIN_VERSION_ghc(9,7,0) | ||
"\\(at ([^)]*)\\)" |
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.
The original regex didn't correctly deal with import lists spanning multiple lines.
Instead of extracting the whole of
"(/path/to/File.hs:(3,1)-(5,2))"
it would only extract
"(/path/to/File.hs:(3,1)"
^ -only up to first `)`
which led to errors in src span parser described in #4175
plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs
Outdated
Show resolved
Hide resolved
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.
LGTM. We have some new tests to ensure we fix the bug too. I think it is good fix.
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.
LGTM, only one suggestion.
More tests are always welcome :)
"\\(at ([^:]+:[^ ]+)\\)" | ||
#else | ||
"\\(([^)]*)\\)" | ||
"\\(([^:]+:[^ ]+)\\)" |
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 this is almost the same, do you think it is a good idea to remove the CPP and use a regex with an optional group like:
"\\((at )?([^:]+:[^ ]+)\\)"
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.
Unfortunately this doesn't work, because it introduces a new capturing group in the regex, which changes the number of matches and because of that it fails the check on this line:
haskell-language-server/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs
Line 1989 in 97aac54
, let result = if length mods == length srcspans then |
I thought I could use non-capturing groups (by adding ?:
insite the parens), but then I learned the regex library we're using only supports posix-compliant regex syntax, so this is not supported.
I also remember that java had a way of specifying the index of the capturing group whose match you want to retrieve, but this doesn't seem to be supporter by regex-tdfa.. actually it is supported, but I don't think using more complicated regex functionality (getting capturing group by index) outweighs the benefit of removing one CPP 🤔
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'll wait for further suggestions if you have any and will merge it in the afternoon otherwise.
Example ghc error corresponding to test case I'm adding: