Skip to content

Commit

Permalink
✨ Add @vanilla-datapack dependency provider
Browse files Browse the repository at this point in the history
  • Loading branch information
SPGoding committed May 14, 2024
1 parent fa3db91 commit f72c6db
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/service/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ export namespace SymbolLinterConfig {
export const VanillaConfig: Config = {
env: {
dataSource: 'GitHub',
dependencies: ['@vanilla-mcdoc'],
dependencies: [
'@vanilla-datapack',
'@vanilla-mcdoc',
],
feature: {
codeActions: true,
colors: true,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/service/FileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ export class ArchiveUriSupporter implements UriProtocolSupporter {
) {
const archiveName = fileUtil.basename(uri)
if (entries.has(archiveName)) {
throw new Error(`A different URI with ${archiveName} already exists`)
throw new Error(
`A different URI with ${archiveName} already exists`,
)
}

const files = await externals.archive.decompressBall(
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/service/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ export class Project implements ExternalEventEmitter {
dependencies,
this.externals,
this.logger,
this.cacheService.checksums.roots,
)
this.fs.register('file:', fileUriSupporter, true)
this.fs.register(
Expand Down
27 changes: 27 additions & 0 deletions packages/java-edition/src/dependency/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ async function downloadGitHubRepo({
}

/* istanbul ignore next */
/**
* @throws Network/file system errors.
*
* @returns
* - `startDepth`: The amount of level to skip when unzipping the tarball.
* - `uri`: URI to the `.tar.gz` file.
*/
export async function getVanillaDatapack(
downloader: core.Downloader,
version: string,
isLatest: boolean,
): Promise<core.Dependency> {
const uri = await downloadGitHubRepo({
defaultBranch: 'data',
downloader,
getTag: (v) => `${v}-data`,
owner: 'misode',
repo: 'mcmeta',
isLatest,
version,
})
return {
info: { startDepth: 1 },
uri,
}
}

/**
* @throws Network/file system errors.
*
Expand Down
6 changes: 6 additions & 0 deletions packages/java-edition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as mcdoc from '@spyglassmc/mcdoc'
import * as nbt from '@spyglassmc/nbt'
import { uriBinder } from './binder/index.js'
import type { McmetaSummary } from './dependency/index.js'
import { getVanillaDatapack } from './dependency/index.js'
import {
getMcmetaSummary,
getVanillaMcdoc,
Expand Down Expand Up @@ -60,6 +61,11 @@ export const initialize: core.ProjectInitializer = async (ctx) => {
versions,
})

meta.registerDependencyProvider(
'@vanilla-datapack',
() => getVanillaDatapack(downloader, version, isLatest),
)

meta.registerDependencyProvider(
'@vanilla-mcdoc',
() => getVanillaMcdoc(downloader),
Expand Down
5 changes: 5 additions & 0 deletions packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ connection.onInitialize(async (params) => {
})
service.project
.on('documentErrored', ({ errors, uri, version }) => {
if (!core.fileUtil.isFileUri(uri)) {
// Don't send errors for non-file URIs to the client.
return
}

connection.sendDiagnostics({
diagnostics: toLS.diagnostics(errors),
uri: uri,
Expand Down

0 comments on commit f72c6db

Please sign in to comment.