Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): bump langium and langium-cli #942

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/safe-ds-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"chalk": "^5.3.0",
"commander": "^12.0.0",
"glob": "^10.3.10",
"langium": "^3.0.0-next.e78aeba",
"langium": "^3.0.0",
"true-myth": "^7.1.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-cli/src/cli/check.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSafeDsServicesWithBuiltins } from '@safe-ds/lang';
import { createSafeDsServices } from '@safe-ds/lang';
import { NodeFileSystem } from 'langium/node';
import { extractDocuments } from '../helpers/documents.js';
import { diagnosticToString, getDiagnostics } from '../helpers/diagnostics.js';
Expand All @@ -7,7 +7,7 @@ import chalk from 'chalk';
import { ExitCode } from './exitCode.js';

export const check = async (fsPaths: string[], options: CheckOptions): Promise<void> => {
const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;

let errorCount = 0;

Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-cli/src/cli/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSafeDsServicesWithBuiltins } from '@safe-ds/lang';
import { createSafeDsServices } from '@safe-ds/lang';
import { NodeFileSystem } from 'langium/node';
import { extractDocuments } from '../helpers/documents.js';
import { exitIfDocumentHasSyntaxErrors } from '../helpers/diagnostics.js';
Expand All @@ -7,7 +7,7 @@ import { writeFile } from 'node:fs/promises';
import chalk from 'chalk';

export const format = async (fsPaths: string[]): Promise<void> => {
const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const documents = await extractDocuments(services, fsPaths);

// Exit if any document has syntax errors before formatting code
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-cli/src/cli/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSafeDsServicesWithBuiltins } from '@safe-ds/lang';
import { createSafeDsServices } from '@safe-ds/lang';
import chalk from 'chalk';
import { URI } from 'langium';
import { NodeFileSystem } from 'langium/node';
Expand All @@ -9,7 +9,7 @@ import { makeParentDirectoriesSync } from '../helpers/files.js';
import { exitIfDocumentHasErrors } from '../helpers/diagnostics.js';

export const generate = async (fsPaths: string[], options: GenerateOptions): Promise<void> => {
const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const documents = await extractDocuments(services, fsPaths);

// Exit if any document has errors before generating code
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-cli/tests/helpers/documents.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { describe, expect, it } from 'vitest';
import { Result } from 'true-myth';
import { processPaths } from '../../src/helpers/documents.js';
import { createSafeDsServicesWithBuiltins } from '@safe-ds/lang';
import { createSafeDsServices } from '@safe-ds/lang';
import { NodeFileSystem } from 'langium/node';
import { fileURLToPath } from 'url';
import path from 'node:path';
import { ExitCode } from '../../src/cli/exitCode.js';

describe('processPaths', async () => {
const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const testResourcesRoot = new URL('../resources/processPaths/', import.meta.url);

const tests: ProcessPathsTest[] = [
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-lang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"chevrotain": "^11.0.3",
"glob": "^10.3.10",
"langium": "^3.0.0-next.e78aeba",
"langium": "^3.0.0",
"semver": "^7.6.0",
"source-map": "^0.7.4",
"tree-kill": "^1.2.2",
Expand All @@ -56,7 +56,7 @@
"devDependencies": {
"@types/node": "^18.18.12",
"@types/ws": "^8.5.10",
"langium-cli": "^3.0.0-next.e78aeba",
"langium-cli": "^3.0.1",
"true-myth": "^7.1.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-ds-lang/src/language/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Services
export type { SafeDsServices } from './safe-ds-module.js';
export { createSafeDsServices, createSafeDsServicesWithBuiltins } from './safe-ds-module.js';
export { createSafeDsServices } from './safe-ds-module.js';

// Language Server
export { startLanguageServer } from './main.js';
Expand Down
56 changes: 24 additions & 32 deletions packages/safe-ds-lang/src/language/safe-ds-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,46 +186,33 @@ export const SafeDsSharedModule: Module<SafeDsSharedServices, DeepPartial<SafeDs
* @param options Further options to configure the Safe-DS module.
* @return An object wrapping the shared services and the language-specific services.
*/
export const createSafeDsServices = function (
export const createSafeDsServices = async function (
context: DefaultSharedModuleContext,
options?: ModuleOptions,
): {
): Promise<{
shared: LangiumSharedServices;
SafeDs: SafeDsServices;
} {
}> {
const shared = inject(createDefaultSharedModule(context), SafeDsGeneratedSharedModule, SafeDsSharedModule);
const SafeDs = inject(createDefaultModule({ shared }), SafeDsGeneratedModule, SafeDsModule);

shared.ServiceRegistry.register(SafeDs);
registerValidationChecks(SafeDs);
SafeDs.runtime.Runner.updateRunnerCommand(options?.runnerCommand);
return { shared, SafeDs };
};

/**
* Create the full set of services required by Langium and load all builtin files into the workspace.
*
* First inject the shared services by merging two modules:
* - Langium default shared services
* - Services generated by langium-cli
*
* Then inject the language-specific services by merging three modules:
* - Langium default language-specific services
* - Services generated by langium-cli
* - Services specified in this file
*
* @param context Optional module context with the LSP connection.
* @param options Further options to configure the Safe-DS module.
* @return An object wrapping the shared services and the language-specific services.
*/
export const createSafeDsServicesWithBuiltins = async function (
context: DefaultSharedModuleContext,
options?: ModuleOptions,
): Promise<{
shared: LangiumSharedServices;
SafeDs: SafeDsServices;
}> {
const { shared, SafeDs } = createSafeDsServices(context, options);
await shared.workspace.WorkspaceManager.initializeWorkspace([]);
// If we don't run inside a language server, initialize the configuration provider instantly
if (!context.connection) {
await shared.workspace.ConfigurationProvider.initialized({});
}

// Apply options
if (!options?.omitBuiltins) {
await shared.workspace.WorkspaceManager.initializeWorkspace([]);
}
if (options?.runnerCommand) {
/* c8 ignore next 2 */
SafeDs.runtime.Runner.updateRunnerCommand(options?.runnerCommand);
}

return { shared, SafeDs };
};

Expand All @@ -234,7 +221,12 @@ export const createSafeDsServicesWithBuiltins = async function (
*/
export interface ModuleOptions {
/**
* Optional command to start the runner, if available.
* By default, builtins are loaded into the workspace. If this option is set to true, builtins are omitted.
*/
omitBuiltins?: boolean;

/**
* Command to start the runner.
*/
runnerCommand?: string;
}
12 changes: 6 additions & 6 deletions packages/safe-ds-lang/tests/helpers/nodeFinder.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { afterEach, describe, expect, it } from 'vitest';
import { getNodeOfType, getNodeByLocation } from './nodeFinder.js';
import { createSafeDsServices } from '../../src/language/safe-ds-module.js';
import { getNodeByLocation, getNodeOfType } from './nodeFinder.js';
import { createSafeDsServices } from '../../src/language/index.js';
import { EmptyFileSystem } from 'langium';
import { AssertionError } from 'assert';
import { clearDocuments, parseHelper } from 'langium/test';
import { isSdsClass, isSdsDeclaration, isSdsEnum } from '../../src/language/generated/ast.js';

describe('getNodeByLocation', () => {
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
describe('getNodeByLocation', async () => {
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;

afterEach(async () => {
await clearDocuments(services);
Expand Down Expand Up @@ -56,8 +56,8 @@ describe('getNodeByLocation', () => {
});
});

describe('getNodeOfType', () => {
const services = createSafeDsServices(EmptyFileSystem).SafeDs;
describe('getNodeOfType', async () => {
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;

afterEach(async () => {
await clearDocuments(services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CODE_EXPERIMENTAL_LANGUAGE_FEATURE } from '../../../src/language/valida
import { locationToString } from '../../../src/helpers/locations.js';
import { loadDocuments } from '../../helpers/testResources.js';

const services = createSafeDsServices(NodeFileSystem).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const langiumDocuments = services.shared.workspace.LangiumDocuments;
const builtinFiles = listBuiltinFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { createSafeDsServices } from '../../../src/language/index.js';
import { getNodeOfType } from '../../helpers/nodeFinder.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const commentProvider = services.documentation.CommentProvider;
const testComment = '/* test */';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createSafeDsServices } from '../../../src/language/index.js';
import { getNodeOfType } from '../../helpers/nodeFinder.js';
import { expandToString } from 'langium/generate';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const documentationProvider = services.documentation.DocumentationProvider;
const testDocumentation = 'Lorem ipsum.';

Expand Down
2 changes: 1 addition & 1 deletion packages/safe-ds-lang/tests/language/flow/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from 'fs';
import { getSyntaxErrors, SyntaxErrorsInCodeError } from '../../helpers/diagnostics.js';
import { findTestChecks } from '../../helpers/testChecks.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const rootResourceName = 'call graph';

export const createCallGraphTests = (): Promise<CallGraphTest[]> => {
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-ds-lang/tests/language/flow/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createSafeDsServices } from '../../../src/language/index.js';
import { EmptyFileSystem } from 'langium';
import { isSdsModule, SdsCallable } from '../../../src/language/generated/ast.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const code = `
fun f1()
fun f2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
SdsCall,
SdsCallable,
} from '../../../src/language/generated/ast.js';
import { createSafeDsServicesWithBuiltins } from '../../../src/language/index.js';
import { createSafeDsServices } from '../../../src/language/index.js';
import { createCallGraphTests } from './creator.js';
import { getNodeOfType } from '../../helpers/nodeFinder.js';
import { isRangeEqual } from 'langium/test';
import { locationToString } from '../../../src/helpers/locations.js';
import { AssertionError } from 'assert';
import { NodeFileSystem } from 'langium/node';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const callGraphComputer = services.flow.CallGraphComputer;

describe('SafeDsCallGraphComputer', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-lang/tests/language/generation/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
uriToShortenedTestResourceName,
} from '../../helpers/testResources.js';
import path from 'path';
import { createSafeDsServicesWithBuiltins } from '../../../src/language/index.js';
import { ErrorsInCodeError, getErrorsAtURI } from '../../helpers/diagnostics.js';
import { findTestChecks } from '../../helpers/testChecks.js';
import { Location } from 'vscode-languageserver';
import { NodeFileSystem } from 'langium/node';
import { TestDescription, TestDescriptionError } from '../../helpers/testDescription.js';
import { locationToString } from '../../../src/helpers/locations.js';
import { URI } from 'langium';
import { createSafeDsServices } from '../../../src/language/index.js';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const langiumDocuments = services.shared.workspace.LangiumDocuments;

const rootResourceName = 'generation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createSafeDsServicesWithBuiltins } from '../../../src/language/index.js';
import { describe, expect, it } from 'vitest';
import { NodeFileSystem } from 'langium/node';
import { createGenerationTests } from './creator.js';
import { loadDocuments } from '../../helpers/testResources.js';
import { stream, URI } from 'langium';
import { createSafeDsServices } from '../../../src/language/index.js';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const langiumDocuments = services.shared.workspace.LangiumDocuments;
const pythonGenerator = services.generation.PythonGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NodeFileSystem } from 'langium/node';
import { createGrammarTests } from './creator.js';
import { getSyntaxErrors } from '../../helpers/diagnostics.js';

const services = createSafeDsServices(NodeFileSystem).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;

describe('grammar', () => {
it.each(createGrammarTests())('$testName', async (test) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../../../src/language/generated/ast.js';
import { escapeString } from '../../../src/language/grammar/safe-ds-value-converter.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;

describe('runConverter', () => {
describe('ID', () => {
Expand Down
Loading