Skip to content

Jsxtags: shaded brackets in JSX, just like TS does. #368

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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b2d5ca3
Test vendoring the entire parser.
cristianoc Jul 7, 2021
af57911
Complete vendoring of necessary compiler libs.
cristianoc Mar 9, 2022
1d3515e
Add test command to parse a file.
cristianoc Mar 9, 2022
8b3a4e7
Separate parser test.
cristianoc Mar 10, 2022
e42016c
Add part of core logic to recognise JSX uppercase/lowercase, type arg…
cristianoc Mar 10, 2022
9b7d8d9
Basic setup of extension analysis bin communication.
cristianoc Mar 11, 2022
d854773
Simple token emitter
cristianoc Mar 11, 2022
5fb6fc2
Pass current file contents to binary command.
cristianoc Mar 11, 2022
6fca52b
Use an ast mapper.
cristianoc Mar 11, 2022
2bf41ca
Semantic highlighting for JSX open and close.
cristianoc Mar 11, 2022
7d18906
Emit variables.
cristianoc Mar 12, 2022
142d03d
Add token type "variable".
cristianoc Mar 12, 2022
547ae25
Emitting types too.
cristianoc Mar 12, 2022
3c5119b
add sample highlight files
zth Mar 12, 2022
31b603e
add explicit semantic token for JSX tag
zth Mar 12, 2022
77dae25
Emit long idents in expressions, patterns, and jsx labels, uniformly.
cristianoc Mar 12, 2022
40a1511
Rename JsxTag to Module.
cristianoc Mar 14, 2022
73879ae
Other cases of module declarations and expressions.
cristianoc Mar 14, 2022
ede6f86
For module types, use Token.Type.
cristianoc Mar 14, 2022
8658618
Add token type to debug print.
cristianoc Mar 14, 2022
4faa239
Use JsxTag for lower-case jsx, and Namespace for modules.
cristianoc Mar 14, 2022
8ec7e31
Extend example file.
cristianoc Mar 14, 2022
6645df7
Extend example.
cristianoc Mar 14, 2022
cc4a0d3
Emit record labels as "property".
cristianoc Mar 14, 2022
a91494f
Emit variants as enumMember.
cristianoc Mar 14, 2022
d4ceba1
change let coloring to keyword, not control
zth Mar 14, 2022
2140178
Merge branch 'semantic-highlighting' of github.com:zth/rescript-vscod…
zth Mar 14, 2022
a9de07c
more samples
zth Mar 14, 2022
e12db8d
Fix issue with function definitions that use labeled arguments.
cristianoc Mar 14, 2022
61408d5
tweak example file
cristianoc Mar 14, 2022
36d6747
Fix recursion in jsx props and children.
cristianoc Mar 14, 2022
1dba34a
Mark identifiers as `variable` by default.
cristianoc Mar 15, 2022
3efe079
Update rescript.tmLanguage.json
cristianoc Mar 15, 2022
bbe1622
Tweak example.
cristianoc Mar 15, 2022
14f7640
set explicit scope for true/false
zth Mar 15, 2022
7a168b1
add nested sample
zth Mar 15, 2022
d0daa2b
add nested sample to TS file as well
zth Mar 15, 2022
0db650c
samples for interpolated strings
zth Mar 15, 2022
779c890
set template-expression scope for interpolated strings
zth Mar 15, 2022
228374c
Tweak test: nested.
cristianoc Mar 16, 2022
b44828c
Fix issue with closing tag of nested components.
cristianoc Mar 16, 2022
9db5562
Semantic highlighting: show brackets in jsx like TypeScript does.
cristianoc Mar 16, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Bindings
let numberBinding = 123

let someFunction = (param: int): int => {
let innerBinding = param + 2
innerBinding
}

// Types
type someRecord<'typeParameter> = {
someField: int,
someOtherField: string,
theParam: typeParameter,
}

type someEnum =
| SomeMember
| AnotherMember
| SomeMemberWithPayload(someRecord<int>)

type somePolyEnum = [
| #someMember
| #AnotherMember
| #SomeMemberWithPayload(someRecord<int>)
| #"fourth Member"
]

// Destructuring
let destructuring = () => {
let someVar = (1, 2, 3)
let (one, two, three) = someVar
let someObj: someRecord<int> = {
someField: 1,
someOtherField: "hello",
theParam: 2,
}
let {someField, someOtherField, theParam} = someObj

someField
}

module SomeModule = {
type t = Some | Value | Here
}

// Strings
let interpolated = `${numberBinding} ${"123"}`

// JSX
module SomeComponent = {
@react.component
let make = (
~someProp: int,
~otherProp: string,
~thirdProp: SomeModule.t,
~fourth: somePolyEnum=#"fourth member",
) => {
React.null
}

module Nested = {
@react.component
let make = (~children) => {
<> {children} </>
}
}
}

let jsx =
<div>
<SomeComponent someProp=123 otherProp="hello" thirdProp=Value fourth=#AnotherMember />
<SomeComponent.Nested> {React.string("Nested")} </SomeComponent.Nested>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Bindings
fn some_function(param: usize) -> usize {
let innerBinding = param + 2;
innerBinding
}

// Types
struct someRecord<typeParameter> {
someField: usize,
someOtherField: String,
theParam: typeParameter,
}

enum someEnum {
SomeMember,
AnotherMember,
SomeMemberWithPayload(someRecord<usize>),
}

// Destructuring
fn destructuring() -> usize {
let someVar = (1, 2, 3);
let (one, two, three) = someVar;
let someObj = someRecord::<usize> {
someField: 1,
someOtherField: String::new("HEllo"),
theParam: 2,
};

someObj.someField
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Bindings
let numberBinding = 123;

const SomeComp = {
Nested: () => null,
};

let someFunction = (param: number): number => {
let innerBinding = param + 2;
return innerBinding;
};

// Types
type someRecord<typeParameter> = {
someField: number;
someOtherField: string;
theParam: typeParameter;
};

enum someEnum {
SomeMember,
AnotherMember,
}

// Destructuring
let destructuring = () => {
let someVar = [1, 2, 3];
let [one, two, three] = someVar;
let someObj: someRecord<number> = {
someField: 1,
someOtherField: "hello",
theParam: 2,
};
let { someField, someOtherField, theParam } = someObj;

return someField;
};

namespace SomeModule {
export enum t {
Some,
Value,
Here,
}
}

// Strings
let interpolated = `${numberBinding} ${"123"}`;

// JSX
interface Props {
someProp: number;
otherProp: string;
thirdProp: SomeModule.t;
}
const SomeComponent = ({ someProp, otherProp, thirdProp }: Props) => {
return null;
};

let jsx = (
<div>
<SomeComponent
someProp={123}
otherProp="hello"
thirdProp={SomeModule.t.Value}
/>
</div>
);
4 changes: 3 additions & 1 deletion analysis/src/Cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ let main () =
~col:(int_of_string col)
| _ :: "dump" :: files -> Commands.dump files
| [_; "documentSymbol"; path] -> Commands.documentSymbol ~path
| [_; "semanticTokens"; currentFile] ->
SemanticTokens.testCommand ~currentFile
| [_; "hover"; path; line; col] ->
Commands.hover ~path ~line:(int_of_string line) ~col:(int_of_string col)
| [_; "references"; path; line; col] ->
Expand All @@ -83,6 +85,6 @@ let main () =
| _ ->
prerr_endline help;
exit 1

;;

main ()
7 changes: 5 additions & 2 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ let test ~path =
print_endline
("Hover " ^ path ^ " " ^ string_of_int line ^ ":"
^ string_of_int col);

hover ~path ~line ~col
| "ref" ->
print_endline
Expand All @@ -331,7 +330,6 @@ let test ~path =
("Rename " ^ path ^ " " ^ string_of_int line ^ ":"
^ string_of_int col ^ " " ^ newName)
in

rename ~path ~line ~col ~newName
| "com" ->
print_endline
Expand All @@ -349,6 +347,11 @@ let test ~path =
close_out cout;
completion ~path ~line ~col ~currentFile;
Sys.remove currentFile
| "par" ->
print_endline ("Parse " ^ path);
SemanticTokens.parser ~debug:true
~emitter:(SemanticTokens.Token.createEmitter ())
~path
| _ -> ());
print_newline ())
in
Expand Down
6 changes: 2 additions & 4 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1276,10 +1276,8 @@ let rec resolvePath ~env ~path ~package =
| Some file ->
resolvePath ~env:(QueryEnv.fromFile file) ~path:fullPath ~package))

let tupleOfLexing {Lexing.pos_lnum; pos_cnum; pos_bol} =
(pos_lnum - 1, pos_cnum - pos_bol)

let locationIsBefore {Location.loc_start} pos = tupleOfLexing loc_start <= pos
let locationIsBefore {Location.loc_start} pos =
Utils.tupleOfLexing loc_start <= pos

let findInScope pos name iter stamps =
(* Log.log("Find " ++ name ++ " with " ++ string_of_int(Hashtbl.length(stamps)) ++ " stamps"); *)
Expand Down
Loading