Skip to content

fix: restore Nim syntax highlighting and syntax menu entry - #3177

Closed
jay23606 wants to merge 2 commits into
Acode-Foundation:mainfrom
jay23606:pr-go/3014-nim-syntax-highlighting-missing-in-the-n
Closed

jay23606 wants to merge 2 commits into
Acode-Foundation:mainfrom
jay23606:pr-go/3014-nim-syntax-highlighting-missing-in-the-n

Conversation

@jay23606

@jay23606 jay23606 commented Dec 5, 2026

Copy link
Copy Markdown

Bug

Nim files are no longer highlighted, and Nim is missing from the syntax menu. The Ace editor's Nim mode was not carried over when the editor moved to CodeMirror, and @codemirror/language-data does not bundle Nim.

Change

  • src/cm/modes/nim/index.ts: a StreamLanguage tokenizer for Nim covering line and block comments (including nested #[ ]#), triple-quoted and regular strings, numeric literals, keywords, atoms and builtin types.
  • src/cm/supportedModes.ts: registers the Nim mode for .nim, .nims and .nimble files, so it appears in the syntax menu.
  • tests/unit/nimHighlighting.test.ts: checks that .nim resolves to the Nim caption, and that the tokenizer colours keywords, types, numbers, strings and comments.

Testing

  • npx vitest run tests/unit/nimHighlighting.test.ts passes (2 tests).
  • With the source changes reverted to the base commit, the same command fails with expected 'Plain Text' to be 'Nim', and the tokenizer test fails because the Nim module is missing.
  • npx biome check src/cm/modes/nim/index.ts src/cm/supportedModes.ts tests/unit/nimHighlighting.test.ts passes.

Regression test: fails on base twice (/expected 'Plain Text' to be 'Nim'/), passes on fix twice (npx vitest run tests/unit/nimHighlighting.test.ts)

Fixes #3014

@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The changes affect the editor workflow for Nim files.

The PR appears safe to merge, with two non-blocking highlighting fixes recommended.

Findings

  1. P2 Raw strings swallow comments ▶
  2. P2 Documentation looks like code ▶

Summary

Adds a Nim language mode and registers .nim, .nims, and .nimble files.

  • Nim files now open with Nim syntax colors and a Nim menu choice.

Reviews (1) · Last reviewed commit: "fix: restore Nim syntax highlighting and..." · Reviewed by Greptile

Comment thread src/cm/modes/nim/index.ts
state.inTripleString = true;
return readTripleString(stream, state);
}
if (stream.match('"')) return readString(stream);

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.

P2 Raw strings swallow comments

For valid Nim such as let path = r"C:\" # note, the prefix is read separately, then readString treats the backslash as escaping the closing quote. The trailing comment is colored as part of the string. Recognize raw and generalized string prefixes before applying ordinary string escapes, and add a regression test.

Comment thread src/cm/modes/nim/index.ts
Comment on lines +122 to +126
if (stream.match("#[")) {
state.blockCommentDepth = 1;
return readBlockComment(stream, state);
}
if (stream.match("#")) {

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.

P2 Documentation looks like code

Nim uses ##[ ... ]## for multiline documentation comments, but ##[ fails the #[ check and falls into the single-line comment branch. The following documentation lines are then colored as code. Recognize documentation comment delimiters before the line-comment branch, track their matching closer, and test a multiline example.

Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@jay23606
jay23606 marked this pull request as draft December 5, 2026 13:17
@bajrangCoder

Copy link
Copy Markdown
Member

#3159 (comment)

@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Nim syntax highlighting missing in the new release

2 participants