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

Let enry decide the filetype unconditionally for code highlighting#56559

Merged
SuperAuguste merged 5 commits into
mainfrom
auguste/enry-highlighting-lang-detection
Sep 19, 2023
Merged

Let enry decide the filetype unconditionally for code highlighting#56559
SuperAuguste merged 5 commits into
mainfrom
auguste/enry-highlighting-lang-detection

Conversation

@SuperAuguste

@SuperAuguste SuperAuguste commented Sep 12, 2023

Copy link
Copy Markdown
Contributor

Closes #56372

Test plan

Add tests.

@cla-bot cla-bot Bot added the cla-signed label Sep 12, 2023
Comment thread lib/codeintel/languages/languages.go Outdated
@SuperAuguste SuperAuguste marked this pull request as ready for review September 18, 2023 14:18
@sourcegraph-bot

sourcegraph-bot commented Sep 18, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 82df680...e6b4430.

Notify File(s)
@efritz lib/codeintel/languages/BUILD.bazel
lib/codeintel/languages/languages.go

Comment thread internal/highlight/language_test.go Outdated
Comment thread internal/highlight/language_test.go Outdated
Comment thread lib/codeintel/languages/languages.go Outdated

@varungandhi-src varungandhi-src Sep 18, 2023

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.

Alternate comment suggestion: Set a soft upper limit on the time spent to determine the language, as this code path is triggered for every syntax highlighting request.

(Optional) Additionally, the number 2048 seems arbitrary; could you roughly benchmark the time spent for some large C++ files? It would be nice to know much time this takes.

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.

Also, add a comment that this number shouldn't be reduced below 755 as the Apache License text has that many characters.

(Otherwise, for .h header files with Apache License headers, we may get confused between C and C++)

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.

Oh I just copied this code from zoekt so I'm not sure what logic they used, but I can look into it if you like.

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.

I don't think it particularly matters what exact reasoning Zoekt used; this code snippet is small enough that we can independently determine what a good limit should be.

Comment thread lib/codeintel/languages/languages.go Outdated
Comment thread internal/highlight/language_test.go Outdated
@varungandhi-src

Copy link
Copy Markdown
Contributor

This looks directionally correct, I've left some minor comments to make things more idiomatic and clearer in terms of why certain decisions were made and what some potential footguns are.

Also, you forgot to add a Test Plan in the PR description, it can be as simple as "Added new unit tests"

@SuperAuguste

Copy link
Copy Markdown
Contributor Author

Thanks @varungandhi-src, this helps a lot! :)

@SuperAuguste SuperAuguste force-pushed the auguste/enry-highlighting-lang-detection branch 2 times, most recently from 967ddca to 489939e Compare September 18, 2023 17:30
@SuperAuguste SuperAuguste force-pushed the auguste/enry-highlighting-lang-detection branch from 489939e to 7c8d961 Compare September 18, 2023 21:08
@SuperAuguste SuperAuguste force-pushed the auguste/enry-highlighting-lang-detection branch from 7c8d961 to 78fc751 Compare September 19, 2023 14:07
@SuperAuguste SuperAuguste force-pushed the auguste/enry-highlighting-lang-detection branch from 78fc751 to 1ef0eb2 Compare September 19, 2023 15:26
@SuperAuguste SuperAuguste enabled auto-merge (squash) September 19, 2023 15:43
@SuperAuguste SuperAuguste merged commit 59ed6a1 into main Sep 19, 2023
@SuperAuguste SuperAuguste deleted the auguste/enry-highlighting-lang-detection branch September 19, 2023 15:50
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.

Consistently highlight Matlab files using the Matlab language grammar

3 participants