Skip to content

Commit

Permalink
fix: use new options of createSafeDsServices to prevent stalls
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Mar 1, 2024
1 parent 5e07712 commit 56981d2
Show file tree
Hide file tree
Showing 58 changed files with 99 additions and 111 deletions.
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
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
1 change: 1 addition & 0 deletions packages/safe-ds-lang/src/language/safe-ds-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const createSafeDsServices = async function (
await shared.workspace.WorkspaceManager.initializeWorkspace([]);
}
if (options?.runnerCommand) {
/* c8 ignore next 2 */
SafeDs.runtime.Runner.updateRunnerCommand(options?.runnerCommand);
}

Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { EmptyFileSystem } from 'langium';
import { describe, expect, it } from 'vitest';
import { isSdsAbstractCall, SdsArgument } from '../../../../src/language/generated/ast.js';
import { getArguments } from '../../../../src/language/helpers/nodeProperties.js';
import { createSafeDsServices } from '../../../../src/language/index.js';
import { createSafeDsServices, getArguments } 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 nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
SdsAssignee,
} from '../../../../src/language/generated/ast.js';
import { getAssignees } from '../../../../src/language/helpers/nodeProperties.js';
import { createSafeDsServicesWithBuiltins } from '../../../../src/language/index.js';
import { getNodeOfType } from '../../../helpers/nodeFinder.js';
import { createSafeDsServices } from '../../../../src/language/index.js';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, expect, it } from 'vitest';
import { isSdsAbstractCall } from '../../../../src/language/generated/ast.js';
import { createSafeDsServicesWithBuiltins } from '../../../../src/language/index.js';
import { getNodeOfType } from '../../../helpers/nodeFinder.js';
import { NodeFileSystem } from 'langium/node';
import { createSafeDsServices } from '../../../../src/language/index.js';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import {
SdsParameter,
SdsPipeline,
} from '../../../../src/language/generated/ast.js';
import { createSafeDsServices } from '../../../../src/language/index.js';
import { createSafeDsServices, getModuleMembers, getParameters } from '../../../../src/language/index.js';
import { Constant, IntConstant } from '../../../../src/language/partialEvaluation/model.js';
import { getNodeOfType } from '../../../helpers/nodeFinder.js';
import { getModuleMembers, getParameters } from '../../../../src/language/helpers/nodeProperties.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const callGraphComputer = services.flow.CallGraphComputer;
const nodeMapper = services.helpers.NodeMapper;
const partialEvaluator = services.evaluation.PartialEvaluator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isSdsParameter } from '../../../../src/language/generated/ast.js';
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 nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
SdsParameter,
SdsPipeline,
} from '../../../../src/language/generated/ast.js';
import { createSafeDsServices } from '../../../../src/language/index.js';
import { createSafeDsServices, getArguments, getModuleMembers, getParameters } from '../../../../src/language/index.js';
import { getNodeOfType } from '../../../helpers/nodeFinder.js';
import { getArguments, getModuleMembers, getParameters } from '../../../../src/language/helpers/nodeProperties.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const callGraphComputer = services.flow.CallGraphComputer;
const nodeMapper = services.helpers.NodeMapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isSdsPlaceholder } from '../../../../src/language/generated/ast.js';
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 nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isSdsResult } from '../../../../src/language/generated/ast.js';
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 nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getTypeArguments } from '../../../../src/language/helpers/nodePropertie
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 nodeMapper = services.helpers.NodeMapper;

describe('SafeDsNodeMapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getSyntaxErrors } from '../../../helpers/diagnostics.js';
import { TestDescription, TestDescriptionError } from '../../../helpers/testDescription.js';
import { listTestSafeDsFiles, uriToShortenedTestResourceName } from '../../../helpers/testResources.js';

const services = createSafeDsServices(EmptyFileSystem).SafeDs;
const services = (await createSafeDsServices(EmptyFileSystem, { omitBuiltins: true })).SafeDs;
const rootResourceName = 'formatting';
const separator = '// -----------------------------------------------------------------------------';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterEach, describe, it } from 'vitest';
import { EmptyFileSystem } from 'langium';
import { createFormattingTests } from './creator.js';

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

describe('formatter', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { NodeFileSystem } from 'langium/node';
import { parseHelper } from 'langium/test';
import { describe, expect, it } from 'vitest';
import { type CallHierarchyItem } from 'vscode-languageserver';
import { createSafeDsServicesWithBuiltins } from '../../../src/language/index.js';
import { findTestRanges } from '../../helpers/testRanges.js';
import { createSafeDsServices } from '../../../src/language/index.js';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const callHierarchyProvider = services.lsp.CallHierarchyProvider!;
const parse = parseHelper(services);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { NodeFileSystem } from 'langium/node';
import { parseDocument, textDocumentParams } from 'langium/test';
import { describe, expect, it } from 'vitest';
import { DocumentSymbol, SymbolKind, SymbolTag } from 'vscode-languageserver';
import { createSafeDsServicesWithBuiltins } from '../../../src/language/index.js';
import { createSafeDsServices } from '../../../src/language/index.js';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const symbolProvider = services.lsp.DocumentSymbolProvider!;

describe('SafeDsSemanticTokenProvider', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, expect, it } from 'vitest';
import { parseHelper } from 'langium/test';
import { createSafeDsServicesWithBuiltins } from '../../../src/language/index.js';
import { InlayHint, Position } from 'vscode-languageserver';
import { NodeFileSystem } from 'langium/node';
import { findTestChecks } from '../../helpers/testChecks.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 inlayHintProvider = services.lsp.InlayHintProvider!;
const parse = parseHelper(services);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NodeFileSystem } from 'langium/node';
import { afterEach, describe, expect, it } from 'vitest';
import { createSafeDsServicesWithBuiltins, getModuleMembers } from '../../../src/language/index.js';
import { createSafeDsServices, getModuleMembers } from '../../../src/language/index.js';
import { clearDocuments } from 'langium/test';
import { SdsModule } from '../../../src/language/generated/ast.js';
import { URI } from 'langium';
import { TextDocument } from 'vscode-languageserver-textdocument';

const services = (await createSafeDsServicesWithBuiltins(NodeFileSystem)).SafeDs;
const services = (await createSafeDsServices(NodeFileSystem)).SafeDs;
const documentBuilder = services.shared.workspace.DocumentBuilder;
const langiumDocuments = services.shared.workspace.LangiumDocuments;
const langiumDocumentFactory = services.shared.workspace.LangiumDocumentFactory;
Expand Down
Loading

0 comments on commit 56981d2

Please sign in to comment.