uiwjs / uiwjs/react-codemirror

foldGutter not working with legacy-mode languages

Open
#382 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

Here is a basic component that renders fold gutters fine. You can see that I'm importing the language from @codemirror/lang-javascript:

import CodeMirror from "@uiw/react-codemirror";
import { duotoneDark } from "@uiw/codemirror-theme-duotone";

import { javascript } from "@codemirror/lang-javascript";

const text =  `function testFold() {
  // some code
}`

export default function Home() {
  return <CodeMirror
    value={text}
    theme={duotoneDark}
    basicSetup={{
      foldGutter: true,
    }}
    extensions={[javascript()]}
  />
}

However if I try to import it from @codemirror/legacy-modes/mode/javascript I can't see any fold gutter :

import CodeMirror from "@uiw/react-codemirror";
import { duotoneDark } from "@uiw/codemirror-theme-duotone";

import { StreamLanguage } from "@codemirror/language"; // new import
import { javascript } from '@codemirror/legacy-modes/mode/javascript'; // new import
    
const text =  `function testFold() {
  // some code
}`

export default function Home() {
  return <CodeMirror
    value={text}
    theme={duotoneDark}
    basicSetup={{
      foldGutter: true,
    }}
    extensions={[StreamLanguage.define(javascript)]} // using StreamLanguage.define
  />
}

I originally had this issue with the shader mode of the clike legacy-mode language, and unlike javascript I didn't find it elsewhere than in the legacy-mode languages.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the legacy-mode setup using StreamLanguage.define(javascript) in the reported @uiw/react-codemirror example, and compare it with the working @codemirror/lang-javascript setup. Inspect how basicSetup enables foldGutter and how the legacy javascript and clike shader modes expose folding. Done means fold gutters appear for legacy-mode languages, including the reported shader case, with the behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.