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

Changing license and fixing client tests #2

Merged
merged 5 commits into from
Jan 29, 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
19 changes: 15 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Install X server
run: |
sudo apt-get update
sudo apt-get install -y xvfb

- name: Install the dependencies
run: npm clean-install && npm run postinstall

Expand All @@ -32,14 +37,20 @@ jobs:
- name: Test language server
run: npm run test:server

- name: Test language server client
run: |
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
npm run test

- name: Package Extension
run: npx vsce package

- name: Archive vsix package
uses: actions/upload-artifact@v4
with:
name: language-server-modelica.vsix
path: language-server-modelica-*.vsix
name: modelica-language-server.vsix
path: modelica-language-server-*.vsix

release:
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -50,13 +61,13 @@ jobs:
steps:
- uses: actions/download-artifact@v4
with:
name: language-server-modelica.vsix
name: modelica-language-server.vsix

- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
language-server-modelica-*.vsix
modelica-language-server-*.vsix
fail_on_unmatched_files: true
generate_release_notes: true
append_body: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.vscode-test
client/server
language-server-modelica*.vsix
modelica-language-server*.vsix
node_modules
out
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"AnHeuermann.metamodelica"
]
}
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// A launch configuration that compiles the extension and then opens it inside a
// new window
{
"version": "0.2.0",
"configurations": [
Expand Down
5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"cSpell.words": [
"Karabel"
]
}
}
660 changes: 660 additions & 0 deletions LICENCE.md

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions LICENSE.md

This file was deleted.

1 change: 1 addition & 0 deletions OSMC-USAGE-MODE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AGPL
59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# VS Code Modelica Language Server
# Modelica Language Server

Heavily documented sample code for https://code.visualstudio.com/api/language-extensions/language-server-extension-guide
[![Build](https://github.com/AnHeuermann/modelica-language-server/actions/workflows/test.yml/badge.svg)](https://github.com/AnHeuermann/modelica-language-server/actions/workflows/test.yml)

A very early version of a Modelica Language Server based on
[OpenModelica/tree-sitter-modelica](https://github.com/OpenModelica/tree-sitter-modelica).

For syntax highlighting install enxtension
[AnHeuermann.metamodelica](https://marketplace.visualstudio.com/items?itemName=AnHeuermann.metamodelica)
in addition.

## Functionality

This Language Server works for Modelica files. It has the following language features:
- None
This Language Server works for Modelica files. It has the following language
features:

- Provide Outline of Modelica files.

It also includes an End-to-End test.
## Installation

Check the Marketplace for
[AnHeuermann.modelica-language-server]((https://marketplace.visualstudio.com/items?itemName=AnHeuermann.modelica-language-server)).

## Structure

Expand All @@ -18,24 +30,26 @@ It also includes an End-to-End test.
│ │ ├── test // End to End tests for Language Client / Server
│ │ └── extension.ts // Language Client entry point
├── package.json // The extension manifest.
└── server // Language Server
└── server // Modelica Language Server
└── src
└── server.ts // Language Server entry point
```

## Running the Language Server
## Building the Language Server

- Run `npm install` in this folder. This installs all necessary npm modules in both the
client and server folder
- Run `npm install` in this folder. This installs all necessary npm modules in
both the client and server folder
- Open VS Code on this folder.
- Press Ctrl+Shift+B to start compiling the client and server in
[watch mode](https://code.visualstudio.com/docs/editor/tasks#:~:text=The%20first%20entry%20executes,the%20HelloWorld.js%20file.).
- Press Ctrl+Shift+B to start compiling the client and server in [watch
mode](https://code.visualstudio.com/docs/editor/tasks#:~:text=The%20first%20entry%20executes,the%20HelloWorld.js%20file.).
- Switch to the Run and Debug View in the Sidebar (Ctrl+Shift+D).
- Select `Launch Client` from the drop down (if it is not already).
- Press ▷ to run the launch config (F5).
- In the [Extension Development Host](https://code.visualstudio.com/api/get-started/your-first-extension#:~:text=Then%2C%20inside%20the%20editor%2C%20press%20F5.%20This%20will%20compile%20and%20run%20the%20extension%20in%20a%20new%20Extension%20Development%20Host%20window.)
- In the [Extension Development
Host](https://code.visualstudio.com/api/get-started/your-first-extension#:~:text=Then%2C%20inside%20the%20editor%2C%20press%20F5.%20This%20will%20compile%20and%20run%20the%20extension%20in%20a%20new%20Extension%20Development%20Host%20window.)
instance of VSCode, open a document in 'modelica' language mode.
- Check the console output of `Language Server Modelica` to see the parsed tree of the opened file.
- Check the console output of `Language Server Modelica` to see the parsed
tree of the opened file.

## Build and Install Extension

Expand All @@ -45,4 +59,21 @@ npx vsce package

## License

See [License.md](./LICENSE.md).
Copyright (C) 2023-2024 Andreas Heuermann, Osman Karabel

modelica-language-server is licensed under the
GNU Affero General Public License v3, see [COPYING.md](./COPYING.md).

### 3rd Party Licenses

This extension is based on
[https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample](https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample),
licensed under MIT license.

Some parts of the source code are taken from
[bash-language-server](https://github.com/bash-lsp/bash-language-server),
licensed under the MIT license, and adapted to the Modelica language server.

[OpenModelica/tree-sitter-modelica](https://github.com/OpenModelica/tree-sitter-modelica)
v0.2.0 is included in this extension and is licensed under the [OSMC-PL
v1.8](./server/OSMC-License.txt) choosing [AGPL mode](./OSMC-USAGE-MODE.txt).
6 changes: 3 additions & 3 deletions client/package-lock.json

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

8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "lsp-sample-client",
"name": "modelica-language-server-client",
"description": "VSCode part of a language server",
"author": "Microsoft Corporation",
"license": "MIT",
"author": "Andreas Heuermann",
"license": "AGPL-3.0-or-later",
"version": "0.0.1",
"publisher": "vscode",
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/vscode-extension-samples"
"url": "https://github.com/AnHeuermann/modelica-language-server"
},
"engines": {
"vscode": "^1.75.0",
Expand Down
62 changes: 52 additions & 10 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
/*
* This file is part of modelica-language-server.
*
* modelica-language-server is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* modelica-language-server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with modelica-language-server. If not, see
* <http://www.gnu.org/licenses/>.
*/

import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';

import { languages, workspace, ExtensionContext, TextDocument } from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind
} from 'vscode-languageclient/node';
import { getFileExtension, getLanguage } from './getLanguage';

let client: LanguageClient;

export function activate(context: ExtensionContext) {
// Register event listener to set language for '.mo' files.
const checkedFiles: { [id: string]: boolean} = {};
workspace.onDidOpenTextDocument((document: TextDocument) => {
if (checkedFiles[document.fileName]) {
return;
}

checkedFiles[document.fileName] = true;
if (getFileExtension(document) == '.mo') {
const lang = getLanguage(document);

switch (lang) {
case 'modelica':
languages.setTextDocumentLanguage(document, 'modelica');
break;
case 'metamodelica':
languages.setTextDocumentLanguage(document, 'metamodelica');
break;
default:
break;
}
}
});

// The server is implemented in node
const serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
Expand All @@ -33,8 +70,13 @@ export function activate(context: ExtensionContext) {

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'modelica' }],
// Register the server for modelica text documents
documentSelector: [
{
language: 'modelica',
scheme: 'file'
}
],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
Expand All @@ -43,8 +85,8 @@ export function activate(context: ExtensionContext) {

// Create the language client and start the client.
client = new LanguageClient(
'languageServerModelica',
'Language Server Modelica',
'modelicaLanguageServer',
'Modelica Language Server',
serverOptions,
clientOptions
);
Expand Down
48 changes: 48 additions & 0 deletions client/src/getLanguage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of modelica-language-server.
*
* modelica-language-server is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* modelica-language-server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with modelica-language-server. If not, see
* <http://www.gnu.org/licenses/>.
*/


import * as path from 'path';
import { TextDocument } from 'vscode';

type LanguageTypes = 'modelica' | 'metamodelica' | 'unknown'

export function getFileExtension(document: TextDocument): string | undefined {
const uri = document.uri;
const filePath = uri.fsPath;
return path.extname(filePath);
}

function hasMetaModelicaKeywords(content: string): boolean {
const unionRegex = new RegExp('\\b(uniontype)\\s+(\\w+)\\s*(".*")*');

return unionRegex.test(content);
}

/**
* Check if the text document is a Modelica files, MetaModelica file or other.
* @param document Text document.
*/
export function getLanguage(document: TextDocument): LanguageTypes {
// Check
if (hasMetaModelicaKeywords(document.getText())) {
return 'metamodelica';
}

return 'modelica';
}
Loading
Loading