Skip to content

Commit

Permalink
Merge pull request #4368 from James-Yu/4365-integration-of-intellisen…
Browse files Browse the repository at this point in the history
…se-data-common-to-the-koma-script-document-classes

Include base KOMA macro/env in KOMA art, book, rept
  • Loading branch information
James-Yu authored Sep 6, 2024
2 parents 62601bd + 6533600 commit e0bdfaf
Show file tree
Hide file tree
Showing 10 changed files with 4,704 additions and 826 deletions.
787 changes: 779 additions & 8 deletions data/packages/class-scrartcl.json

Large diffs are not rendered by default.

787 changes: 779 additions & 8 deletions data/packages/class-scrbook.json

Large diffs are not rendered by default.

787 changes: 779 additions & 8 deletions data/packages/class-scrreprt.json

Large diffs are not rendered by default.

780 changes: 3 additions & 777 deletions dev/packages/class-scrartcl,scrreprt,scrbook.json

Large diffs are not rendered by default.

787 changes: 779 additions & 8 deletions dev/packages/class-scrartcl.json

Large diffs are not rendered by default.

787 changes: 779 additions & 8 deletions dev/packages/class-scrbook.json

Large diffs are not rendered by default.

787 changes: 779 additions & 8 deletions dev/packages/class-scrreprt.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion dev/parse-cwl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,24 @@ function findArg(arg: string, regexp: RegExp, index: number): string | false {
* @returns The parsed package object.
*/
function parsePkg(pkgName: string): PackageRaw {
const content = fs.readFileSync(`cwl/${pkgName}.cwl`).toString()
let content = fs.readFileSync(`cwl/${pkgName}.cwl`).toString()
content = handleKomaClasses(pkgName, content)
const pkg: PackageRaw = { deps: [], macros: [], envs: [], keys: {}, args: [] }
parseLines(pkg, content.split('\n'))
return pkg
}

function handleKomaClasses(pkgName: string, content: string): string {
if (!['class-scrartcl', 'class-scrbook', 'class-scrreprt', 'class-scrartcl,scrreprt,scrbook'].includes(pkgName)) {
return content
}
if (pkgName === 'class-scrartcl,scrreprt,scrbook') {
return ''
}
const baseContent = fs.readFileSync('cwl/class-scrartcl,scrreprt,scrbook.cwl').toString()
return baseContent + '\n' + content
}

/**
* Parses an array of file paths and converts CWL files to JSON format.
*
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/armory/intellisense/koma.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\documentclass{scrartcl}
\begin{document}
\end{document}
11 changes: 11 additions & 0 deletions test/suites/04_intellisense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,15 @@ suite('Intellisense test suite', () => {
assert.ok(undefined === suggestions.items.find(item => item.label === '#+' && item.insertText instanceof vscode.SnippetString && item.insertText.value === '\\bigcup'))
assert.ok(undefined === suggestions.items.find(item => item.label === '#8'))
})

test.run('suggest base KOMAScript macros/envs in KOMAScript class', async (fixture: string) => {
await test.load(fixture, [
{src: 'intellisense/koma.tex', dst: 'main.tex'}
])
const suggestions = test.suggest(0, 1)
// in class-scrartcl.cwl
assert.ok(suggestions.labels.includes('\\addpart{}'))
// in base
assert.ok(suggestions.labels.includes('\\addchap{}'))
})
})

0 comments on commit e0bdfaf

Please sign in to comment.