Skip to content

Commit

Permalink
feat: separate VS Code languages for pipeline/stub/tests (#1043)
Browse files Browse the repository at this point in the history
### Summary of Changes

* Pipeline files, stub files, and test files now get assigned separate
language IDs in VS Code. This is needed to better control various
activation events.
* Change the file extension `.sdspipe` to `.sds`. It's what users
actually interact with, so it should be short.
* Change the file extension `.sdstest` to `.sdsdev`. `sdstest` might
have suggested that users can use this to test their programs.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lars-reimann and megalinter-bot authored Apr 14, 2024
1 parent bb57481 commit 8147480
Show file tree
Hide file tree
Showing 1,684 changed files with 497 additions and 279 deletions.
2 changes: 1 addition & 1 deletion docs/development/testing/call-graph-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ graph test.

## Adding a call graph test

1. Create a new file with the extension `.sdstest` in the `tests/resources/call graph` directory or any subdirectory.
1. Create a new file with the extension `.sdsdev` in the `tests/resources/call graph` directory or any subdirectory.
Give the file a descriptive name, since the file name becomes part of the test name.

!!! tip "Skipping a test"
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing/formatting-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ formatting test.

## Adding a formatting test

1. Create a new file with the extension `.sdstest` in the `tests/resources/formatting` directory or any subdirectory.
1. Create a new file with the extension `.sdsdev` in the `tests/resources/formatting` directory or any subdirectory.
Give the file a descriptive name, since the file name becomes part of the test name.

!!! tip "Skipping a test"
Expand Down
4 changes: 2 additions & 2 deletions docs/development/testing/generation-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ document explains how to add a new generation test.

If you want to skip a test, add the prefix `skip-` to the folder name.

2. Add files with the extension `.sdstest`, `.sdspipe`, or `.sdsstub` **directly inside the folder**. All files in a
2. Add files with the extension `.sdsdev`, `.sds`, or `.sdsstub` **directly inside the folder**. All files in a
folder will be loaded into the same workspace, so they can reference each other. Files in different folders are
loaded into different workspaces, so they cannot reference each other. Generation will be triggered for all files in
the folder.
Expand Down Expand Up @@ -48,7 +48,7 @@ To quickly update the expected output after changes to the code generator, run `

If you want to skip a test, add the prefix `skip-` to the folder name.

2. Add files with the extension `.sdstest`, `.sdspipe`, or `.sdsstub` **directly inside the folder**. All files in a
2. Add files with the extension `.sdsdev`, `.sds`, or `.sdsstub` **directly inside the folder**. All files in a
folder will be loaded into the same workspace, so they can reference each other. Files in different folders are
loaded into different workspaces, so they cannot reference each other. Generation will be triggered for all files in
the folder.
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing/grammar-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test.

## Adding a grammar test

1. Create a new file with the extension `.sdstest` in the `tests/resources/grammar` directory or any subdirectory. Give
1. Create a new file with the extension `.sdsdev` in the `tests/resources/grammar` directory or any subdirectory. Give
the file a descriptive name, since the file name becomes part of the test name.

!!! note "Naming convention"
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing/partial-evaluation-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ partial evaluation test.

If you want to skip a test, add the prefix `skip-` to the folder name.

2. Add files with the extension `.sdstest` **directly inside the folder**. All files in a folder will be loaded into the
2. Add files with the extension `.sdsdev` **directly inside the folder**. All files in a folder will be loaded into the
same workspace, so they can reference each other. Files in different folders are loaded into different workspaces, so
they cannot reference each other.
3. Add the Safe-DS code that you want to test to the files.
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing/scoping-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.

If you want to skip a test, add the prefix `skip-` to the folder name.

2. Add files with the extension `.sdstest` **directly inside
2. Add files with the extension `.sdsdev` **directly inside
the folder**. All files in a folder will be loaded into the same workspace, so they can
reference each other. Files in different folders are loaded into different workspaces, so they cannot reference each other.
3. Add the Safe-DS code that you want to test to the files.
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing/typing-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.

If you want to skip a test, add the prefix `skip-` to the folder name.

2. Add files with the extension `.sdstest` **directly inside the folder**. All files in a folder will be loaded into the
2. Add files with the extension `.sdsdev` **directly inside the folder**. All files in a folder will be loaded into the
same workspace, so they can reference each other. Files in different folders are loaded into different workspaces, so
they cannot reference each other.
3. Add the Safe-DS code that you want to test to the files.
Expand Down
2 changes: 1 addition & 1 deletion docs/development/testing/validation-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ validation test.

If you want to skip a test, add the prefix `skip-` to the folder name.

2. Add files with the extension `.sdstest`, `.sdspipe`, or `.sdsstub` **directly inside the folder**. All files in a
2. Add files with the extension `.sdsdev`, `.sds`, or `.sdsstub` **directly inside the folder**. All files in a
folder will be loaded into the same workspace, so they can reference each other. Files in different folders are
loaded into different workspaces, so they cannot reference each other.
3. Add the Safe-DS code that you want to test to the files.
Expand Down
4 changes: 2 additions & 2 deletions docs/language/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

The Safe-DS DSL is split into two main parts:

- The _[pipeline language][pipeline-language]_ is used to solve specific data science problems. Unless you want to add functionality to Safe-DS, this sublanguage is all you need to learn. To use the pipeline language, create a file with the extension `.sdspipe`.
- The _[pipeline language][pipeline-language]_ is used to solve specific data science problems. Unless you want to add functionality to Safe-DS, this sublanguage is all you need to learn. To use the pipeline language, create a file with the extension `.sds`.
- The _[stub language][stub-language]_ is used to integrate external code written in Python into Safe-DS, so it can be used in the [pipeline language][pipeline-language]. The main purpose of this sublanguage is to define the [Safe-DS Standard Library (stdlib)][stdlib]. To use the stub language, create a file with the extension `.sdsstub`.

[pipeline-language]: pipeline-language/README.md
[stub-language]: stub-language/README.md
[stdlib]: https://github.com/lars-reimann/Safe-DS/blob/main/DSL/com.larsreimann.safeds/src/main/resources/stdlib
[stdlib]: https://github.com/Safe-DS/DSL/blob/main/packages/safe-ds-lang/src/resources/builtins
2 changes: 1 addition & 1 deletion docs/language/pipeline-language/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The pipeline language is the part of the Safe-DS DSL that is designed to solve s
- [Expressions][expressions] are computations that produce some value.
- [Comments][comments] document the code.

Files that use the pipeline language must have the extension `.sdspipe`.
Files that use the pipeline language must have the extension `.sds`.

[packages]: ../common/packages.md
[imports]: ../common/imports.md
Expand Down
2 changes: 1 addition & 1 deletion docs/lexer/safe_ds_lexer/_safe_ds_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SafeDsLexer(RegexLexer):
"SDS",
"sds",
]
filenames = ["*.sdspipe", "*.sdsstub", "*.sdstest"]
filenames = ["*.sds", "*.sdsstub", "*.sdsdev"]

tokens = {
"root": [
Expand Down
24 changes: 12 additions & 12 deletions packages/safe-ds-cli/tests/cli/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,25 @@ describe('safe-ds', () => {
});

it('should show not show errors in correct files', () => {
const process = spawnCheckProcess([], ['correct.sdstest']);
const process = spawnCheckProcess([], ['correct.sdsdev']);
expect(process.stdout.toString()).toContain('No errors found.');
expect(process.status).toBe(ExitCode.Success);
});

it('should handle references to builtins', () => {
const process = spawnCheckProcess([], ['references builtins.sdstest']);
const process = spawnCheckProcess([], ['references builtins.sdsdev']);
expect(process.stdout.toString()).toContain('No errors found.');
expect(process.status).toBe(ExitCode.Success);
});

it('should treat warnings as errors in strict mode', () => {
const process = spawnCheckProcess(['-s'], ['contains warnings.sdstest']);
const process = spawnCheckProcess(['-s'], ['contains warnings.sdsdev']);
expect(process.stderr.toString()).toMatch(/Found \d+ errors?\./u);
expect(process.status).toBe(ExitCode.FileHasErrors);
});

it('should show an error if the file does not exist', () => {
const process = spawnCheckProcess([], ['missing.sdstest']);
const process = spawnCheckProcess([], ['missing.sdsdev']);
expect(process.stderr.toString()).toMatch(/Path .* does not exist\./u);
expect(process.status).toBe(ExitCode.MissingPath);
});
Expand Down Expand Up @@ -124,19 +124,19 @@ describe('safe-ds', () => {
});

it('should generate Markdown documentation', () => {
const process = spawnDocumentProcess([], ['correct.sdstest']);
const process = spawnDocumentProcess([], ['correct.sdsdev']);
expect(process.stdout.toString()).toContain('Markdown documentation generated successfully.');
expect(process.status).toBe(ExitCode.Success);
});

it('should generate Markdown documentation (Safe-DS code references builtins)', () => {
const process = spawnDocumentProcess([], ['references builtins.sdstest']);
const process = spawnDocumentProcess([], ['references builtins.sdsdev']);
expect(process.stdout.toString()).toContain('Markdown documentation generated successfully.');
expect(process.status).toBe(ExitCode.Success);
});

it('should show an error if the file does not exist', () => {
const process = spawnDocumentProcess([], ['missing.sdstest']);
const process = spawnDocumentProcess([], ['missing.sdsdev']);
expect(process.stderr.toString()).toMatch(/Path .* does not exist./u);
expect(process.status).toBe(ExitCode.MissingPath);
});
Expand Down Expand Up @@ -184,13 +184,13 @@ describe('safe-ds', () => {
});

it('should show not show errors in correct files', () => {
const process = spawnFormatProcess([], ['correct.sdstest']);
const process = spawnFormatProcess([], ['correct.sdsdev']);
expect(process.stdout.toString()).toContain('Safe-DS code formatted successfully.');
expect(process.status).toBe(ExitCode.Success);
});

it('should show an error if the file does not exist', () => {
const process = spawnFormatProcess([], ['missing.sdstest']);
const process = spawnFormatProcess([], ['missing.sdsdev']);
expect(process.stderr.toString()).toMatch(/Path .* does not exist\./u);
expect(process.status).toBe(ExitCode.MissingPath);
});
Expand Down Expand Up @@ -233,19 +233,19 @@ describe('safe-ds', () => {
});

it('should generate Python code', () => {
const process = spawnGenerateProcess([], ['correct.sdstest']);
const process = spawnGenerateProcess([], ['correct.sdsdev']);
expect(process.stdout.toString()).toContain('Python code generated successfully.');
expect(process.status).toBe(ExitCode.Success);
});

it('should generate Python code (Safe-DS code references builtins)', () => {
const process = spawnGenerateProcess([], ['references builtins.sdstest']);
const process = spawnGenerateProcess([], ['references builtins.sdsdev']);
expect(process.stdout.toString()).toContain('Python code generated successfully.');
expect(process.status).toBe(ExitCode.Success);
});

it('should show an error if the file does not exist', () => {
const process = spawnGenerateProcess([], ['missing.sdstest']);
const process = spawnGenerateProcess([], ['missing.sdsdev']);
expect(process.stderr.toString()).toMatch(/Path .* does not exist./u);
expect(process.status).toBe(ExitCode.MissingPath);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/safe-ds-cli/tests/helpers/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('diagnosticToString', () => {
range,
message,
},
expected: chalk.red(`test.sdstest:1:1: [error] message`),
expected: chalk.red(`test.sdsdev:1:1: [error] message`),
},
{
testName: 'warning',
Expand All @@ -35,7 +35,7 @@ describe('diagnosticToString', () => {
range,
message,
},
expected: chalk.yellow(`test.sdstest:1:1: [warning] message`),
expected: chalk.yellow(`test.sdsdev:1:1: [warning] message`),
},
{
testName: 'warning (strict)',
Expand All @@ -47,7 +47,7 @@ describe('diagnosticToString', () => {
options: {
strict: true,
},
expected: chalk.red(`test.sdstest:1:1: [warning] message`),
expected: chalk.red(`test.sdsdev:1:1: [warning] message`),
},
{
testName: 'info',
Expand All @@ -56,7 +56,7 @@ describe('diagnosticToString', () => {
range,
message,
},
expected: chalk.blue(`test.sdstest:1:1: [info] message`),
expected: chalk.blue(`test.sdsdev:1:1: [info] message`),
},
{
testName: 'hint',
Expand All @@ -65,7 +65,7 @@ describe('diagnosticToString', () => {
range,
message,
},
expected: chalk.gray(`test.sdstest:1:1: [hint] message`),
expected: chalk.gray(`test.sdsdev:1:1: [hint] message`),
},
{
testName: 'with code',
Expand All @@ -75,12 +75,12 @@ describe('diagnosticToString', () => {
message,
code: 'CODE',
},
expected: chalk.red(`test.sdstest:1:1: [error] message (CODE)`),
expected: chalk.red(`test.sdsdev:1:1: [error] message (CODE)`),
},
];

it.each(tests)('$testName', ({ diagnostic, options, expected }) => {
const uri = URI.file(path.join(process.cwd(), 'test.sdstest'));
const uri = URI.file(path.join(process.cwd(), 'test.sdsdev'));
const actual = diagnosticToString(uri, diagnostic, options);
expect(actual).toBe(expected);
});
Expand Down
24 changes: 12 additions & 12 deletions packages/safe-ds-cli/tests/helpers/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe('processPaths', async () => {
const tests: ProcessPathsTest[] = [
{
testName: 'pipe file',
paths: ['a.sdspipe'],
expected: Result.ok(['a.sdspipe']),
paths: ['a.sds'],
expected: Result.ok(['a.sds']),
},
{
testName: 'stub file',
Expand All @@ -24,29 +24,29 @@ describe('processPaths', async () => {
},
{
testName: 'test file',
paths: ['c.sdstest'],
expected: Result.ok(['c.sdstest']),
paths: ['c.sdsdev'],
expected: Result.ok(['c.sdsdev']),
},
{
testName: 'multiple files',
paths: ['a.sdspipe', 'b.sdsstub', 'c.sdstest'],
expected: Result.ok(['a.sdspipe', 'b.sdsstub', 'c.sdstest']),
paths: ['a.sds', 'b.sdsstub', 'c.sdsdev'],
expected: Result.ok(['a.sds', 'b.sdsstub', 'c.sdsdev']),
},
{
testName: 'duplicates',
paths: ['a.sdspipe', 'a.sdspipe'],
expected: Result.ok(['a.sdspipe']),
paths: ['a.sds', 'a.sds'],
expected: Result.ok(['a.sds']),
},
{
testName: 'directory',
paths: ['.'],
expected: Result.ok([
'a.sdspipe',
'a.sds',
'b.sdsstub',
'c.sdstest',
'nested/a.sdspipe',
'c.sdsdev',
'nested/a.sds',
'nested/b.sdsstub',
'nested/c.sdstest',
'nested/c.sdsdev',
]),
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-ds-cli/tests/helpers/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { uriToRelativePath } from '../../src/helpers/files.js';

describe('uriToRelativePath', () => {
it('should return a path that is relative to the current working directory', () => {
const fileName = 'test.sdstest';
const fileName = 'test.sdsdev';
const uri = URI.file(path.join(process.cwd(), fileName));

expect(uriToRelativePath(uri)).toBe(fileName);
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-ds-lang/langium-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"id": "safe-ds",
"grammar": "src/language/grammar/safe-ds.langium",
"fileExtensions": [".sdspipe", ".sdsstub", ".sdstest"]
"fileExtensions": [".sds", ".sdsstub", ".sdsdev"]
}
],
"out": "src/language/generated"
Expand Down
22 changes: 11 additions & 11 deletions packages/safe-ds-lang/src/language/helpers/fileExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AstNode, AstUtils, LangiumDocument } from 'langium';
* @see isInPipelineFile
* @see isPipelineFile
*/
export const PIPELINE_FILE_EXTENSION = 'sdspipe';
export const PIPELINE_FILE_EXTENSION = 'sds';

/**
* Marks the file as a stub file, which describes an external API.
Expand All @@ -17,23 +17,23 @@ export const PIPELINE_FILE_EXTENSION = 'sdspipe';
export const STUB_FILE_EXTENSION = 'sdsstub';

/**
* Marks the file as a test file, which disables some checks to simplify its use as input of test cases. This file
* Marks the file as a dev file, which disables some checks to simplify its use as input of test cases. This file
* type is only used by language developers.
*
* @see isInTestFile
* @see isTestFile
* @see isInDevFile
* @see isDevFile
*/
export const TEST_FILE_EXTENSION = 'sdstest';
export const DEV_FILE_EXTENSION = 'sdsdev';

/**
* All file extensions that are supported by the Safe-DS language.
*/
export const SAFE_DS_FILE_EXTENSIONS = [PIPELINE_FILE_EXTENSION, STUB_FILE_EXTENSION, TEST_FILE_EXTENSION];
export const SAFE_DS_FILE_EXTENSIONS = [PIPELINE_FILE_EXTENSION, STUB_FILE_EXTENSION, DEV_FILE_EXTENSION];

/**
* All file extensions that are supported by the Safe-DS language.
*/
export type SdSFileExtension = typeof PIPELINE_FILE_EXTENSION | typeof STUB_FILE_EXTENSION | typeof TEST_FILE_EXTENSION;
export type SdSFileExtension = typeof PIPELINE_FILE_EXTENSION | typeof STUB_FILE_EXTENSION | typeof DEV_FILE_EXTENSION;

/**
* Returns whether the object is contained in a pipeline file.
Expand All @@ -46,9 +46,9 @@ export const isInPipelineFile = (node: AstNode | undefined) => node && isPipelin
export const isInStubFile = (node: AstNode | undefined) => node && isStubFile(AstUtils.getDocument(node));

/**
* Returns whether the object is contained in a test file.
* Returns whether the object is contained in a dev file.
*/
export const isInTestFile = (node: AstNode | undefined) => node && isTestFile(AstUtils.getDocument(node));
export const isInDevFile = (node: AstNode | undefined) => node && isDevFile(AstUtils.getDocument(node));

/**
* Returns whether the resource represents a pipeline file.
Expand All @@ -61,9 +61,9 @@ export const isPipelineFile = (document: LangiumDocument) => hasExtension(docume
export const isStubFile = (document: LangiumDocument) => hasExtension(document, STUB_FILE_EXTENSION);

/**
* Returns whether the resource represents a test file.
* Returns whether the resource represents a dev file.
*/
export const isTestFile = (document: LangiumDocument) => hasExtension(document, TEST_FILE_EXTENSION);
export const isDevFile = (document: LangiumDocument) => hasExtension(document, DEV_FILE_EXTENSION);

/**
* Returns whether the resource represents a file with the given extension.
Expand Down
Loading

0 comments on commit 8147480

Please sign in to comment.