Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Graph: Support JSX syntax highlighting#62027

Merged
mmanela merged 6 commits into
mainfrom
mmanela/ENG-20458
Apr 22, 2024
Merged

Graph: Support JSX syntax highlighting#62027
mmanela merged 6 commits into
mainfrom
mmanela/ENG-20458

Conversation

@mmanela

@mmanela mmanela commented Apr 19, 2024

Copy link
Copy Markdown
Contributor

Fixes ENG-20458
Fixes https://github.com/sourcegraph/sourcegraph/issues/50596

Adds support to highlight JSX files. Adds new SCM file for jsx.

image

Test plan

  • Added unit test
  • Manual testing

@@ -0,0 +1,2 @@
;; This file inherits from javascript/highlights.scm
(jsx_attribute (property_identifier) @identifier.attribute)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@varungandhi-src This is the only thing we were specifically highlighting in our tsx file so I kept this the same here

@varungandhi-src varungandhi-src left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the source of truth, we rely on languages.yml in Linguist, because language detection going forward is based on go-enry, which in turn is based on Linguist. Yes, there is some old code relying on language detection from syntect, but we want to rely on that less with time.

https://sourcegraph.com/github.com/github-linguist/linguist/-/blob/lib/linguist/languages.yml

You'll notice that TSX and TypeScript are listed as separate languages there, whereas the 'jsx' file extension is present on JavaScript. So we should not introduce a new language/ParserId for JSX here, we should instead:

  1. Add the JSX-specific query to the existing JavaScript queries
  2. Make sure that .jsx files are getting mapped to JavaScript in the language detection code in our Go wrapper code for go-enry in package languages.

When JavaScript (or javascript) is passed as the language from the Go code, we should use the correct Tree-sitter grammar automatically.


var baseHighlightConfig = syntaxHighlightConfig{
Extensions: map[string]string{
"jsx": "jsx", // default `getLanguage()` helper doesn't handle JSX

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not needed, since go-enry properly returns jsx as javascript which is what we want

@mmanela mmanela requested a review from varungandhi-src April 20, 2024 02:39
@varungandhi-src

Copy link
Copy Markdown
Contributor

I noticed that the SCIP kind was copied from tsx/highlights.scm and it was incorrect there too. So I've fixed the SCIP kinds (see scip.proto for descriptions https://github.com/sourcegraph/scip/blob/main/scip.proto#L582-L583). It looks like @identifier.attribute is actually being misused in a bunch of queries, we should fix those later.

Updated screenshots in light mode and dark mode.

CleanShot 2024-04-22 at 12 00 54@2x
CleanShot 2024-04-22 at 11 58 54@2x

Comment thread internal/highlight/language_test.go
@mmanela mmanela marked this pull request as ready for review April 22, 2024 16:39
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
@sourcegraph-bot

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@mmanela mmanela merged commit 2f57b2d into main Apr 22, 2024
@mmanela mmanela deleted the mmanela/ENG-20458 branch April 22, 2024 19:05
sourcegraph-release-bot pushed a commit that referenced this pull request Apr 23, 2024
Adds support to highlight JSX files.

Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
(cherry picked from commit 2f57b2d)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Highlighting doesn't work for .jsx files

3 participants