Skip to content

Fix: don't emit object keys in uppercase as namespace #798

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

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#### :bug: Bug Fix

- Fix invalid range for `definition`. https://github.com/rescript-lang/rescript-vscode/pull/781
- Don't emit object keys in uppercase as namespace. https://github.com/rescript-lang/rescript-vscode/pull/798

## 1.18.0

Expand Down
13 changes: 10 additions & 3 deletions analysis/src/SemanticTokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ let emitFromLoc ~loc ~type_ emitter =

let emitLongident ?(backwards = false) ?(jsx = false)
?(lowerCaseToken = if jsx then Token.JsxLowercase else Token.Variable)
?(upperCaseToken = Token.Namespace) ?(lastToken = None) ?(posEnd = None) ~pos
~lid ~debug emitter =
?(upperCaseToken = Token.Namespace) ?(lastToken = None) ?(posEnd = None)
~pos ~lid ~debug emitter =
let rec flatten acc lid =
match lid with
| Longident.Lident txt -> txt :: acc
Expand Down Expand Up @@ -309,7 +309,14 @@ let command ~debug ~emitter ~path =
Ast_iterator.default_iterator.expr iterator e
| Pexp_record (cases, _) ->
cases
|> List.iter (fun (label, _) -> emitter |> emitRecordLabel ~label ~debug);
|> List.filter_map (fun ((label : Longident.t Location.loc), _) ->
match label.txt with
| Longident.Lident s
when String.length s > 0
&& not (Char.equal s.[0] (Char.uppercase_ascii s.[0])) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this a util (or do we already have one for it)? I can see this being useful elsewhere too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 7a24abd

Some label
| _ -> None)
|> List.iter (fun label -> emitter |> emitRecordLabel ~label ~debug);
Ast_iterator.default_iterator.expr iterator e
| Pexp_field (_, label) | Pexp_setfield (_, label, _) ->
emitter |> emitRecordLabel ~label ~debug;
Expand Down
2 changes: 2 additions & 0 deletions analysis/tests/src/Highlight.res
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ let _ = 3 == 3 || 3 === 3
let _ = (~_type_ as _) => ()

let _ = {"abc": 34}

let _ = {"Key": 2}
2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Highlight.res.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Highlight src/Highlight.res
structure items:38 diagnostics:0
structure items:39 diagnostics:0
Lident: M 0:7 Namespace
Lident: C 1:9 Namespace
Lident: Component 1:13 Namespace
Expand Down