Skip to content

Adding Typst mode - #2278

Open
Pythonpoison48 wants to merge 17 commits into
lem-project:mainfrom
Pythonpoison48:main
Open

Adding Typst mode#2278
Pythonpoison48 wants to merge 17 commits into
lem-project:mainfrom
Pythonpoison48:main

Conversation

@Pythonpoison48

Copy link
Copy Markdown

Hello,

I propose to add a typst mode.
it has Tree-sitter support
Lsp-mode support via tinymist
html preview using tinymist
pdf export via typst compile
formatting via typstyle

Copilot AI lite review requested due to automatic review settings August 26, 2026 15:42
@code-contractor-app

code-contractor-app Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Commit b19d0e4 has not been validated yet. The results below are for a previous commit. Comment /rerun (keeps dismissed violations dismissed) or @code-contractor-app to re-validate.

📌 Result for commit f1ad59e

⚠️ Violations Found (1):

[WARNING] max_total_changed_lines
  Too many lines changed: 826 > 400
  Limit: 400
  Actual: 826


ℹ️ 1 violation(s) dismissed


💬 Feedback

Reply to a violation comment with:

  • /dismiss <reason> - Report false positive or not applicable

🔁 Re-validation

Validation does not re-run automatically when you push fixes. Trigger it with one of:

  • Comment /rerun to re-run validation (dismissed violations stay dismissed)
  • Click Run Validation on the Code Contractor check in the Checks tab
  • Comment @code-contractor-app on this pull request

To reset all dismissals and re-judge every violation, comment /revalidate instead (restores previously dismissed violations; requires write permission).

📚 About Code Contractor

Declarative Code Standards That Learn and Improve

Define domain-specific validation rules in YAML.
Your contracts document team knowledge and evolve into more accurate AI enforcement.

Want this for your repo?
Install Code Contractor

@code-contractor-app code-contractor-app Bot 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.

Code Contractor validation failed ❌ — see the sticky comment for full results.

(ok (lem:get-command 'lem-typst-mode/preview/preview:typst-export-file)
"typst-export-file command should be registered")))

(defparameter +typst-suite-sample+

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.

Code Contractor: file_structure_rule

Contract: contract

AI check failed: "file_structure_rule"

Reason:
A defparameter is introduced after function/test definitions, which violates the required top-to-bottom ordering of declarations before functions and commands.


💬 Reply /dismiss <reason> to dismiss this violation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

/dismiss not functionally important

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.

Dismissed by @Pythonpoison48


📝 This feedback will be used to improve rules.
Thank you for your contribution.
View on Dashboard

(in-package :lem-typst-mode/preview/preview)

;;; Variables
(defvar *typst-preview-sessions* (make-hash-table :test 'equal))

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.

Code Contractor: functional_style_rule

Contract: contract

AI check failed: "functional_style_rule"

Reason:
The change introduces new mutable global state with defvar and shares it across functions and commands instead of passing state explicitly.


💬 Reply /dismiss <reason> to dismiss this violation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

/dismiss not practical in this instance

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.

Dismissed by @Pythonpoison48


📝 This feedback will be used to improve rules.
Thank you for your contribution.
View on Dashboard

:depends-on ("lem-typst-mode" "rove")
:components ((:module "tests"
:components ((:file "main"))))
:perform (test-op (op c) (symbol-call :rove '#:run c)))

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.

Code Contractor: dynamic_symbol_call_rule

Contract: contract

AI check failed: "dynamic_symbol_call_rule"

Reason:
The added ASDF test hook uses dynamic symbol invocation via symbol-call.


💬 Reply /dismiss <reason> to dismiss this violation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

/dismiss seems used in other extensions so I take the initiative to dismiss

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.

Dismissed by @Pythonpoison48


📝 This feedback will be used to improve rules.
Thank you for your contribution.
View on Dashboard

"str" "table" "text" "type"))

(defun tokens (boundary strings)
(let ((alternation

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.

Code Contractor: macro_style_rule

Contract: contract

AI check failed: "macro_style_rule"

Reason:
The added tokens function uses backquoted list construction outside a macro, which this rule disallows in favor of explicit list-building.


💬 Reply /dismiss <reason> to dismiss this violation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

/dismiss this pattern is used in a number of other modes so I think I can dismiss safely

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.

Dismissed by @Pythonpoison48


📝 This feedback will be used to improve rules.
Thank you for your contribution.
View on Dashboard

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Typst major mode to Lem as an extension, wiring in syntax highlighting (tmLanguage + tree-sitter queries), LSP support via tinymist, preview/export commands, and basic automated tests to validate mode registration and scanning behavior.

Changes:

  • Introduces lem-typst-mode (major mode + syntax table + formatter hook) and registers it for .typ / .typst.
  • Adds tree-sitter highlight/indent queries and an LSP language spec for tinymist.
  • Adds preview/export commands plus both extension-local and top-level test coverage; registers the extension in the main ASDF systems.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/typst-mode.lisp Adds Lem-level tests for Typst mode registration, file associations, syntax scanning, and command presence.
lem.asd Registers lem-typst-mode in the main system extension list.
lem-tests.asd Adds lem-typst-mode as a dependency and includes the new Typst test file.
extensions/typst-mode/typst-mode.lisp Implements typst-mode, syntax table, tmLanguage patterns, formatter hook, and file-type associations.
extensions/typst-mode/tree-sitter/indents.scm Adds tree-sitter indentation query captures for Typst.
extensions/typst-mode/tree-sitter/highlights.scm Adds tree-sitter highlight captures for Typst grammar nodes.
extensions/typst-mode/tests/main.lisp Adds extension-level tests for mode registration, file associations, and syntax scanning.
extensions/typst-mode/preview/preview.lisp Adds interactive commands for tinymist preview lifecycle and typst PDF export.
extensions/typst-mode/lsp-config.lisp Registers an LSP language spec for Typst using tinymist.
extensions/typst-mode/lem-typst-mode.asd Defines the new extension ASDF system and its test system.
Suppressed comments (1)

lem.asd:269

  • There is another whitespace-only line here (line 268 contains spaces only). It should be removed to avoid trailing whitespace in the ASDF file.
               "lem-toml-mode"
               
               "lem-yaml-mode"

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +55 to +56
(make-tm-match "\\\\\"")
(make-tm-string-region "\"")
Comment thread lem.asd
Comment on lines 264 to 266
"lem-clojure-mode"

"lem-patch-mode"
Comment thread extensions/typst-mode/lem-typst-mode.asd
Comment thread lem.asd Outdated
"lem-html-mode"
"lem-vue-mode"
"lem-typescript-mode"
"lem-typst-mode"
Comment thread tests/typst-mode.lisp
;;;; Test Utilities

(defun make-typst-buffer (content)
"Create a temporary buffer with Typst content and typst-mode enabled."
Comment thread extensions/typst-mode/preview/preview.lisp
Comment thread extensions/typst-mode/preview/preview.lisp Outdated
@vindarel

vindarel commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Can you please add a README with what this does and how-to use instructions, for users? (basically your PR comment)

Also you can answer the code contractor and /dismiss if it's wrong.

@Pythonpoison48

Copy link
Copy Markdown
Author

Thank you for your advices ! I will do that asap

@code-contractor-app code-contractor-app Bot 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.

✅ All violations have been dismissed. This PR is ready to merge.

@vindarel

vindarel commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Hey, when I create a .typst file I get a spinning wheel that won't stop (related to a JSON spec error message IIRC),

but when I re-open the file, the moment I move the cursor everything is highlighted as an error:

Selection_494

Does that ring a bell?

@Pythonpoison48

Pythonpoison48 commented Sep 2, 2026

Copy link
Copy Markdown
Author

Hello I think it's the \ " that causes this problem when I try your example with just "a4" it doesn't give me any error but when I type \ "a4\ " it does. For the json I will investigate this later this evening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants