Repository navigation
feat: smart completion, hover and go-to-definition for koishi.yml - #7
Merged
Merged
Conversation
Extend the extension from structural YAML validation into real language
support for koishi.yml.
Completion
- Field names at the cursor's level, in schema declaration order, with the
description, type and numeric constraints as documentation.
- Enum values on the value side of a field (`prefixMode`, `i18n.output`),
inserted pre-quoted.
- Plugin names inside the `plugins` block, from a bundled snapshot of the
official plugins merged with what is installed in the current workspace.
Hover
- Schema description, type, allowed values and constraints for a field.
- The npm package and declared services for a plugin entry.
Go to definition
- From a plugin name to the installed package's package.json.
Implementation notes
- The YAML AST cannot express a key that is still being typed, nor the empty
value slot after `key:`. cursorAt therefore distinguishes the two by AST
walk plus an indentation fallback, which is what decides whether field or
enum suggestions are offered.
- Plugin discovery follows symlinks so plugins developed with `yarn link`
are recognised.
Also fixes the test infrastructure, which could not run: tsconfig excluded
src/test, so `yarn test` never found compiled tests, and the Mocha runner used
the removed callable `glob` export. Adds .vscode-test to .gitignore.
master picked up #8, which independently fixes the same Yarn 4 problems this branch had worked around, and does so more completely: it pins yarn via packageManager, regenerates the lockfile for Yarn 4, and makes CI actually run the tests and the package step. Resolved by taking #8's version of both conflicts: - package.json: #8 folds compile and lint into `test` and passes --no-yarn to vsce. Yarn 4 no longer runs the implicit pretest hook, so the previous pretest script would have silently stopped running. Re-applied only this branch's feature metadata (categories, keywords, activationEvents, the yaml dependency). - src/test/suite/index.ts: #8's globSync version is simpler and equivalent. Kept the .sort() this branch had, so test order does not depend on the order the filesystem reports. yarn.lock needed no resolution and came out byte-identical to this branch's: both sides converged on the same content. Verified the same way CI will: yarn install --immutable, yarn test (63 passing), and yarn package, which now succeeds and produces a 254 KB vsix.
CI failed after the merge with "Cannot find module schemata/koishi-yml.json". The schemata are generated from schemata/*.yaml by `yarn run convert` and are gitignored, so a clean CI checkout has no JSON. `yarn test` compiled and ran the suite without ever invoking convert, and both schema.test.ts and providers.test.ts load the schema at module scope, so every test file threw before Mocha could report anything useful. - test: run `yarn run convert` before the suite, since the schema is a build artifact of the .yaml sources - SchemaIndex.fromFile: report a missing schema with the command that generates it, instead of letting require() fail with a bare module error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the extension from structural YAML validation of
koishi.ymlinto reallanguage support: field / enum / plugin-name completion, hover
documentation, and go to definition.
koishi.ymlFeatures
Completion
fields stay grouped, with description, type and numeric constraints as
documentation.
prefixMode,i18n.output),inserted pre-quoted.
pluginsblock — a bundled snapshot of theofficial plugins merged with whatever is installed in the current workspace,
so third-party plugins appear too. Each item shows the npm package name and
the services the plugin provides or requires.
Hover
adapter-qqcan be traced back to
@koishijs/plugin-adapter-qq.Go to definition
package.jsoninnode_modules.Design notes
The three providers share one cursor → config-path resolution
(
KoishiYamlDocument.cursorAt), returningpath,parentPathandonKey.Two YAML shapes cannot be expressed by the AST and drove most of the design:
plugins:/ada,adaparses as a scalar value of
plugins, and at the document root(
delay) as a stray scalar with no parent. Neither form says "a key is beingentered", so indentation is used as the signal.
prefixMode: |must read as a valueposition, otherwise enum completion never fires — which is the whole point of
being there.
Getting this wrong in either direction is silent: field names leak into the
value side, or completion returns nothing at all while typing the first field of
a file. Both directions are covered by tests.
Merged with #8
masterpicked up #8, which independently fixes the Yarn 4 issues this branchhad also hit. This branch was rebased onto it and both conflicts resolved in
#8's favour, since #8 is the more complete fix:
package.json— fix: restore yarn test and yarn package on Yarn 4 #8 folds compile and lint intotest(Yarn 4 dropped theimplicit
pretesthook, so the oldpretestscript would have stoppedrunning) and passes
--no-yarnto vsce. Only this branch's feature metadatawas re-applied.
src/test/suite/index.ts— fix: restore yarn test and yarn package on Yarn 4 #8'sglobSyncversion is simpler and equivalent.Kept the
.sort()so test order does not depend on filesystem ordering.yarn.lockneeded no resolution: both sides converged on identical content.Because of #8, two items previously noted here as pre-existing are now fixed:
yarn install --immutablepasses against the committed lockfile, andyarn packageworks. The vsix is 255 KB rather than the 497 KB this branchproduced before, since #8 excludes
.yarn/**from the package.One follow-up fix
#8 made CI run the tests for the first time, which immediately surfaced a real
problem:
schemata/*.jsonis gitignored and generated byyarn run convert,which
yarn testnever invoked, so on a clean checkout every test file threwCannot find module schemata/koishi-yml.jsonbefore Mocha reported anything.testnow runsconvertfirst, andSchemaIndex.fromFilenames the command torun when a schema is absent rather than surfacing a bare module error.
Validation
Run the same way CI does:
yarn install --immutable— passesyarn test(compile + convert + lint + tests) — 63 passing in a real VS Codeinstance, confirmed in the CI log
yarn package— succeeds;yamlverified present in the packaged outputVerified from a clean state by deleting the generated JSON and re-running, which
is the case CI actually hits.
Tests are layered:
schema.test.ts(pure logic),plugins.test.ts(logic plustemp dirs),
providers.test.ts(each provider invoked inside VS Code).Note for review
The bundled plugin list is a static snapshot rather than a live registry query,
so completion stays instant and works offline; workspace-installed plugins
override it, which keeps newer releases covered.