Skip to content

Semantic syntax highlighting #367

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 68 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e42f480
Add test command to parse a file.
cristianoc Mar 9, 2022
bae0ce6
Separate parser test.
cristianoc Mar 10, 2022
cba7ba6
Add part of core logic to recognise JSX uppercase/lowercase, type arg…
cristianoc Mar 10, 2022
b1c3d0a
Basic setup of extension analysis bin communication.
cristianoc Mar 11, 2022
7bf6819
Simple token emitter
cristianoc Mar 11, 2022
c042982
Pass current file contents to binary command.
cristianoc Mar 11, 2022
c837fc3
Use an ast mapper.
cristianoc Mar 11, 2022
097872c
Semantic highlighting for JSX open and close.
cristianoc Mar 11, 2022
c3fa076
Emit variables.
cristianoc Mar 12, 2022
d1537db
Add token type "variable".
cristianoc Mar 12, 2022
763494f
Emitting types too.
cristianoc Mar 12, 2022
4653dda
add sample highlight files
zth Mar 12, 2022
071b273
add explicit semantic token for JSX tag
zth Mar 12, 2022
a197476
Emit long idents in expressions, patterns, and jsx labels, uniformly.
cristianoc Mar 12, 2022
a66eb03
Rename JsxTag to Module.
cristianoc Mar 14, 2022
f11f682
Other cases of module declarations and expressions.
cristianoc Mar 14, 2022
e557d68
For module types, use Token.Type.
cristianoc Mar 14, 2022
167f7ce
Add token type to debug print.
cristianoc Mar 14, 2022
931af3d
Use JsxTag for lower-case jsx, and Namespace for modules.
cristianoc Mar 14, 2022
0a59a79
change let coloring to keyword, not control
zth Mar 14, 2022
8bbe1d0
Extend example file.
cristianoc Mar 14, 2022
14ff85f
Extend example.
cristianoc Mar 14, 2022
eb5bd2b
Emit record labels as "property".
cristianoc Mar 14, 2022
ec34078
Emit variants as enumMember.
cristianoc Mar 14, 2022
4428025
more samples
zth Mar 14, 2022
ae08682
Fix issue with function definitions that use labeled arguments.
cristianoc Mar 14, 2022
bcb131f
tweak example file
cristianoc Mar 14, 2022
dcaa38c
Fix recursion in jsx props and children.
cristianoc Mar 14, 2022
29c843f
Mark identifiers as `variable` by default.
cristianoc Mar 15, 2022
cf7b9b3
Update rescript.tmLanguage.json
cristianoc Mar 15, 2022
dada994
Tweak example.
cristianoc Mar 15, 2022
0cdd154
set explicit scope for true/false
zth Mar 15, 2022
23a4ff4
add nested sample
zth Mar 15, 2022
f59d960
add nested sample to TS file as well
zth Mar 15, 2022
5aeb00e
samples for interpolated strings
zth Mar 15, 2022
411dce0
set template-expression scope for interpolated strings
zth Mar 15, 2022
0dbba2a
Tweak test: nested.
cristianoc Mar 16, 2022
cda4866
Fix issue with closing tag of nested components.
cristianoc Mar 16, 2022
ff13a67
Semantic highlighting: show brackets in jsx like TypeScript does.
cristianoc Mar 16, 2022
1d6a0f5
Handle < in <div via semantic highlighting.
cristianoc Mar 16, 2022
ef69aed
Emit binary operators < and > as keyword, just like other operators.
cristianoc Mar 16, 2022
fca46a3
Fix lowercase jsx.
cristianoc Mar 16, 2022
c5fb591
add braces, and booleans to sample highlighting
zth Mar 16, 2022
2941a60
color annotations like decorators in TS
zth Mar 16, 2022
265e849
Fix true/false.
cristianoc Mar 16, 2022
b0349c0
add to keyword as record prop in highlight examples
zth Mar 16, 2022
71a7801
Don't crash when an id is the empty string.
cristianoc Mar 17, 2022
d371779
Use the grammar to highlight when to/downto are used as labels.
cristianoc Mar 17, 2022
7c0b297
Clean up jsx grammar and comment jsx code.
cristianoc Mar 17, 2022
1e07625
More robust jsx self-closing test.
cristianoc Mar 17, 2022
814a656
Handle quoted Pexp_ident.
cristianoc Mar 17, 2022
c1f574b
True/false: pattern case was missing.
cristianoc Mar 17, 2022
a321a9b
Example with enum in module.
cristianoc Mar 17, 2022
e3d93ce
Fix issue with enum in module.
cristianoc Mar 17, 2022
ccf81fc
Fix issue where type paths longer than 1 were not emitted.
cristianoc Mar 17, 2022
ecda4c1
Update grammar for poly variants, and semantic analysis for types #..…
cristianoc Mar 17, 2022
30c922a
Highlight operators.
cristianoc Mar 18, 2022
373aead
Fix: ! is represented internally as "not".
cristianoc Mar 18, 2022
1fdec92
Fix == and ===.
cristianoc Mar 18, 2022
4001ffe
dummy commit to see if CI runs
zth Mar 19, 2022
2b96d8f
Labels can have underscore.
cristianoc Mar 18, 2022
d735fb1
Added explanatory comments on top of SemanticTokens.ml.
cristianoc Mar 18, 2022
2d7fcd1
ci?
zth Mar 19, 2022
ff026ef
Fix object fields (and clean uo quoted ids).
cristianoc Mar 20, 2022
9bd8ba3
Clean up textmate grammar.
cristianoc Mar 22, 2022
55b9166
Hipster themes are more into `class` than `namespace`.
cristianoc Mar 22, 2022
8282458
rename test
cristianoc Mar 23, 2022
c5d9f45
Clean up cli.
cristianoc Mar 23, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ analysis/tests/.bsb.lock
analysis/_build
analysis/tests/.merlin
analysis/rescript-editor-analysis.exe

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Bindings
let numberBinding = 123

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

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

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,
another: true,
to: "123",
}
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,94 @@
// 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;
another: boolean;
to: string;
};

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,
another: true,
to: "123",
};
let { someField, someOtherField, theParam } = someObj;

return someField;
};

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

// Decorators and classes
function someDecorator() {
return function (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
console.log("first(): called");
};
}

class SomeClass {
@someDecorator() doStuff() {
return 123;
}
}

// 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}
/>
<SomeComp.Nested />
{"Hello"}
</div>
);
function Property() {
throw new Error("Function not implemented.");
}
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.semanticTokens ~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
| "hig" ->
print_endline ("Highlight " ^ path);
SemanticTokens.command ~debug:true
~emitter:(SemanticTokens.Token.createEmitter ())
~path
| _ -> ());
print_newline ())
in
Expand Down
Loading