Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ee52849

Browse files
committedApr 1, 2025·
feat: add test and import suggestion for not in scope record field
In ghc 9.6 we had: ``` Not in scope ‘modelStatusTag’ ``` In 9.10 we have: ``` Not in scope: record field ‘modelStatusTag’ ``` Introducing the new regex in order to match it AND a test to ensure no future regression. The regression is due to the fact that there is a matcher which catch `Nat in scope: .*`, hence it was matching "record" instead of "modelStatusTag".
1 parent 2b27964 commit ee52849

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

+4
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,10 @@ extractNotInScopeName x
18701870
= Just $ NotInScopeThing name
18711871
| Just [_module, name] <- matchRegexUnifySpaces x "No instance for [‘(].*HasField \"[^\"]+\" \\(([^ .]+\\.)*([^ .]+)[^)]*\\).*[’)]"
18721872
= Just $ NotInScopeThing name
1873+
-- The order of the "Not in scope" is important, for example, some of the
1874+
-- matcher may catch the "record" value instead of the value later.
1875+
| Just [name] <- matchRegexUnifySpaces x "Not in scope: record field [^‘]*‘([^’]*)’"
1876+
= Just $ NotInScopeThing name
18731877
| Just [name] <- matchRegexUnifySpaces x "ot in scope: \\(([^‘ ]+)\\)"
18741878
= Just $ NotInScopeThing name
18751879
| Just [name] <- matchRegexUnifySpaces x "ot in scope: ([^‘ ]+)"

‎plugins/hls-refactor-plugin/test/Main.hs

+4
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,10 @@ suggestAddRecordFieldImportTests = testGroup "suggest imports of record fields w
19121912
extractNotInScopeNameTests :: TestTree
19131913
extractNotInScopeNameTests =
19141914
testGroup "extractNotInScopeName" [
1915+
testGroup "record field" [
1916+
testCase ">=ghc 910" $ Refactor.extractNotInScopeName "Not in scope: ‘foo’" @=? Just (NotInScopeThing "foo"),
1917+
testCase "<ghc 910" $ Refactor.extractNotInScopeName "Not in scope: record field ‘foo’" @=? Just (NotInScopeThing "foo")
1918+
],
19151919
testGroup "HasField" [
19161920
testGroup "unqualified" [
19171921
testGroup "nice ticks" [

0 commit comments

Comments
 (0)
Please sign in to comment.