Skip to content

[Bug report] notation word highlight causes twoslash to throw #432

Description

@Mister-Hope

Description

A simple reproduction can be fond at https://github.com/vuepress/ecosystem/tree/shiki-error

However, this is not the exact reproduction I ran into downstream. In current reproduction, error is thrown in code block that both has a notation word highlight and twoslash declaration.

 ShikiError: Invalid decoration offset: 62. Code length: 60
    at normalizePosition (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+core@3.2.1/node_modules/@shikijs/core/dist/index.mjs:291:19)
    at file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+core@3.2.1/node_modules/@shikijs/core/dist/index.mjs:311:16
    at Array.map (<anonymous>)
    at getContext (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+core@3.2.1/node_modules/@shikijs/core/dist/index.mjs:309:61)
    at Object.tokens (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+core@3.2.1/node_modules/@shikijs/core/dist/index.mjs:328:19)
    at codeToHast (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+core@3.2.1/node_modules/@shikijs/core/dist/index.mjs:1176:34)
    at Object.codeToHast (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+core@3.2.1/node_modules/@shikijs/core/dist/index.mjs:1384:38)
    at Object.highlightPopupContent (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+twoslash@3.2.1_typescript@5.8.3/node_modules/@shikijs/twoslash/dist/core.mjs:646:22)
    at Object.nodeStaticInfo (file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+twoslash@3.2.1_typescript@5.8.3/node_modules/@shikijs/twoslash/dist/core.mjs:727:51)
    at file:///home/mister-hope/projects/vuepress/ecosystem/node_modules/.pnpm/@shikijs+twoslash@3.2.1_typescript@5.8.3/node_modules/@shikijs/twoslash/dist/core.mjs:1292:66 

import { shikiPlugin } from '@vuepress/plugin-shiki'
import { defineUserConfig } from 'vuepress'

export default defineUserConfig({
  // Set language you are using
  lang: 'en-US',
  plugins: [shikiPlugin()],
})

In my theme hope repo however, I do not use any word notation highlight at all, but enabling this makes every twoslash code block to throw.

Try clone the main branch and uncomment // notationWordHighlight: true in docs/theme/src/.vuepress/theme.ts, and you will see similar error (after patching shiki plugin similarly)

Reproduction

https://github.com/vuepress/ecosystem/tree/shiki-error

Used Package Manager

pnpm

System Info

.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions