Skip to content

Commit

Permalink
Merge branch 'main' into yokozuna/add-more-services-to-statemachine
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokozuna59 authored Apr 24, 2024
2 parents 86306a2 + 3a5a539 commit d90ada5
Show file tree
Hide file tree
Showing 316 changed files with 19,980 additions and 10,465 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@
"block",
{ "pattern": "MIT License|DO NOT EDIT MANUALLY!" }
],
"no-restricted-imports": ["error", {
"paths": [{
"name": "vscode-jsonrpc",
"importNames": [ "CancellationToken" ],
"message": "Import 'CancellationToken' via 'Cancellation.CancellationToken' from 'langium', or directly from './utils/cancellation.ts' within Langium."
}, {
"name": "vscode-jsonrpc/",
"importNames": [ "CancellationToken"],
"message": "Import 'CancellationToken' via 'Cancellation.CancellationToken' from 'langium', or directly from './utils/cancellation.ts' within Langium."
}],
"patterns": [ {
"group": [ "vscode-jsonrpc" ],
"importNamePattern": "^(?!CancellationToken)",
"message": "Don't import types or symbols from 'vscode-jsonrpc' (package index), as that brings a large overhead in bundle size. Import from 'vscode-jsonrpc/lib/common/...js' and add a // eslint-disable..., if really necessary."
}]
}],
// List of [@typescript-eslint rules](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules)
"@typescript-eslint/adjacent-overload-signatures": "error", // grouping same method names
"@typescript-eslint/array-type": ["error", { // string[] instead of Array<string>
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
run: |
npm ci
npm run build:clean
npm run validate-exports
- name: Test
if: success() || failure()
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"langium.langium-vscode",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"zixuanchen.vitest-explorer"
"vitest.explorer"
]
}
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
"${workspaceFolder}/{packages,examples}/*/{lib,out}/**/*.js"
]
},
{
"name": "Run Yeoman Generator",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/examples",
"runtimeExecutable": "npx",
"runtimeArgs": [
"yo",
"langium"
],
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
],
},
{
"name": "Bootstrap",
"type": "node",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ We maintain separate change logs for the individual packages:

## Closed Issues and PRs

* [v3.0.0](https://github.com/eclipse-langium/langium/milestone/11?closed=1)
* [v2.1.0](https://github.com/eclipse-langium/langium/milestone/10?closed=1)
* [v2.0.0](https://github.com/eclipse-langium/langium/milestone/9?closed=1)
* [v1.3.0](https://github.com/eclipse-langium/langium/milestone/7?closed=1)
Expand Down
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@

Thank you for your interest in the Langium project! The following is a set of guidelines for contributing to Langium.

## Code of Conduct

This project is governed by the [Eclipse Community Code of Conduct](https://github.com/eclipse/.github/blob/master/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.

## Eclipse Contributor Agreement

If you're planning to contribute to this or any other repository in the [`eclipse-langium` GitHub organization](https://github.com/eclipse-langium), please sign the [Eclipse Contributor Agreement (ECA)](https://www.eclipse.org/legal/ECA.php).

By signing the ECA you promise that your contributions adhere to the license used in the repository of the corresponding Eclipse project. This ensures that Langium can be used by any adopter without any legal issues.

For more information, see the [Eclipse Foundation Project Handbook](https://www.eclipse.org/projects/handbook/#resources-commit).

## Communication

The following communication channels are available:

* [GitHub issues](https://github.com/eclipse-langium/langium/issues) – for bug reports, feature requests, etc.
* [GitHub discussions](https://github.com/eclipse-langium/langium/discussions) – for questions, ideas, announcements, etc.
* [Weekly dev meeting](https://github.com/eclipse-langium/langium/discussions/564?sort=new) – for project-related discussions
* [Gitter chat](https://app.gitter.im/#/room/#langium:gitter.im) – for questions
* [Developer mailing list](https://accounts.eclipse.org/mailing-list/langium-dev) – for organizational issues (e.g. elections of new committers)

In case you have a question, please look into the [documentation](https://langium.org/docs/) first. If you don't find any answer there, feel free to use the discussions or chat to get help.

## Prerequisites

For developing Langium you require at least the Maintenance LTS version of Node.js (currently 16) and at least npm version 7.7.0 (`npm@^7.7.0`) to be able to use npm workspaces. With Node.js versions below 16 you have to install the correct version of npm with `npm install -g npm@7`.
For developing Langium, you require at least Node.js version 16 and at least npm version 7.7.0 to be able to use npm workspaces.

## Local Development Guide

Expand Down
1 change: 1 addition & 0 deletions examples/arithmetics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The Arithmetics Example features an interpreter that you can run via cli.
The interpreter calculates each Evaluation in the source file and prints the result.

You also can use `arithmetics-cli` as a replacement for `node ./bin/cli`, if you install the cli globally.

* Run `npm install -g ./` from the arithmetics directory.
* Use `arithmetics-cli` or `arithmetics-cli eval <full-path-to-calc-file>`.

Expand Down
19 changes: 19 additions & 0 deletions examples/arithmetics/example/recursions.calc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Module recursions

def fun1(x):
fun1(x) + fun2(x) + fun2(x) + fun3(x);

def fun2(x):
fun3(x) + fun4(x);

def fun3(x):
3*x;

def fun4(x):
fun3(x) + fun1(x);

def fun5(x):
fun6(x);

def fun6(x):
fun5(x);
10 changes: 5 additions & 5 deletions examples/arithmetics/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "langium-arithmetics-dsl",
"displayName": "Arithmetics DSL",
"version": "2.1.0",
"version": "3.0.0",
"description": "Example language built with Langium",
"homepage": "https://langium.org",
"engines": {
Expand Down Expand Up @@ -69,16 +69,16 @@
"dependencies": {
"chalk": "~5.3.0",
"commander": "~11.0.0",
"langium": "~2.1.0",
"langium": "~3.0.0",
"vscode-languageclient": "~9.0.1",
"vscode-languageserver": "~9.0.1"
},
"devDependencies": {
"langium-cli": "~2.1.0"
"langium-cli": "~3.0.3"
},
"volta": {
"node": "18.17.1",
"npm": "9.6.7"
"node": "18.19.1",
"npm": "10.2.4"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions examples/arithmetics/src/cli/cli-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { AstNode, LangiumDocument, LangiumServices } from 'langium';
import type { AstNode, LangiumDocument, LangiumCoreServices } from 'langium';
import { URI } from 'langium';
import * as fs from 'node:fs';
import * as path from 'node:path';
import chalk from 'chalk';

export async function extractDocument<T extends AstNode>(fileName: string, extensions: readonly string[], services: LangiumServices): Promise<LangiumDocument<T>> {
export async function extractDocument<T extends AstNode>(fileName: string, extensions: readonly string[], services: LangiumCoreServices): Promise<LangiumDocument<T>> {
if (!extensions.includes(path.extname(fileName))) {
console.error(chalk.yellow(`Please, choose a file with one of these extensions: ${extensions}.`));
process.exit(1);
Expand All @@ -21,7 +21,7 @@ export async function extractDocument<T extends AstNode>(fileName: string, exten
process.exit(1);
}

const document = services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(path.resolve(fileName)));
const document = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(path.resolve(fileName)));
await services.shared.workspace.DocumentBuilder.build([document], { validation: true });

const validationErrors = (document.diagnostics ?? []).filter(e => e.severity === 1);
Expand All @@ -38,6 +38,6 @@ export async function extractDocument<T extends AstNode>(fileName: string, exten
return document as LangiumDocument<T>;
}

export async function extractAstNode<T extends AstNode>(fileName: string, extensions: string[], services: LangiumServices): Promise<T> {
export async function extractAstNode<T extends AstNode>(fileName: string, extensions: string[], services: LangiumCoreServices): Promise<T> {
return (await extractDocument(fileName, extensions, services)).parseResult.value as T;
}
11 changes: 2 additions & 9 deletions examples/arithmetics/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node.js';
import * as vscode from 'vscode';
import type * as vscode from 'vscode';
import * as path from 'node:path';
import { LanguageClient, TransportKind } from 'vscode-languageclient/node.js';

Expand Down Expand Up @@ -37,16 +37,9 @@ function startLanguageClient(context: vscode.ExtensionContext): LanguageClient {
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};

const fileSystemWatcher = vscode.workspace.createFileSystemWatcher('**/*.calc');
context.subscriptions.push(fileSystemWatcher);

// Options to control the language client
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'arithmetics' }],
synchronize: {
// Notify the server about file changes to files contained in the workspace
fileEvents: fileSystemWatcher
}
documentSelector: [{ scheme: 'file', language: 'arithmetics' }]
};

// Create the language client and start the client.
Expand Down
13 changes: 9 additions & 4 deletions examples/arithmetics/src/language-server/arithmetics-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { DefaultSharedModuleContext, LangiumServices, LangiumSharedServices, Module, PartialLangiumServices } from 'langium';
import { createDefaultModule, createDefaultSharedModule, inject } from 'langium';
import { ArithmeticsGeneratedModule, ArithmeticsGeneratedSharedModule } from './generated/module.js';
import { ArithmeticsValidator, registerValidationChecks } from './arithmetics-validator.js';
import { type Module, inject } from 'langium';
import { createDefaultModule, createDefaultSharedModule, type DefaultSharedModuleContext, type LangiumServices, type LangiumSharedServices, type PartialLangiumServices } from 'langium/lsp';
import { ArithmeticsScopeProvider } from './arithmetics-scope-provider.js';
import { ArithmeticsValidator, registerValidationChecks } from './arithmetics-validator.js';
import { ArithmeticsGeneratedModule, ArithmeticsGeneratedSharedModule } from './generated/module.js';

/**
* Declaration of custom services - add your own service classes here.
Expand Down Expand Up @@ -69,5 +69,10 @@ export function createArithmeticsServices(context: DefaultSharedModuleContext):
);
shared.ServiceRegistry.register(arithmetics);
registerValidationChecks(arithmetics);
if (!context.connection) {
// We don't run inside a language server
// Therefore, initialize the configuration provider instantly
shared.workspace.ConfigurationProvider.initialized({});
}
return { shared, arithmetics };
}
13 changes: 11 additions & 2 deletions examples/arithmetics/src/language-server/arithmetics-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { BinaryExpression } from './generated/ast.js';
import type { ResolvedReference } from 'langium';
import { isDefinition, type BinaryExpression, type Definition, type FunctionCall } from './generated/ast.js';

export function applyOp(op: BinaryExpression['operator']): (x: number, y: number) => number {
switch (op) {
Expand All @@ -21,4 +22,12 @@ export function applyOp(op: BinaryExpression['operator']): (x: number, y: number
};
default: throw new Error('Unknown operator: ' + op);
}
}
}

export type ResolvedFunctionCall = FunctionCall & {
func: ResolvedReference<Definition>
}

export function isResolvedFunctionCall(functionCall: FunctionCall): functionCall is ResolvedFunctionCall {
return isDefinition(functionCall.func.ref);
}
Loading

0 comments on commit d90ada5

Please sign in to comment.