Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
],
rules: {
'semi': [2, "always"],
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-unused-vars': ["warn"],
'@typescript-eslint/no-unused-expressions': ["warn"],
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-non-null-assertion': 0,
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Build package
run: npm run esbuild

- name: ESLint
run: npm run lint

- name: Test language server
run: npm run test:server

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ features:

![Outline](images/outline_demo.png)

- Hover provider for declared symbols.

![Hover](images/hover_demo.png)

## Installation

### Via Marketplace
Expand Down
1 change: 0 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
TransportKind,
} from 'vscode-languageclient/node';
import { getFileExtension, getLanguage } from './getLanguage';
import { fstat } from 'fs';

let client: LanguageClient;

Expand Down
105 changes: 105 additions & 0 deletions client/src/test/onHover.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
* VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the OSMC (Open Source Modelica Consortium)
* Public License (OSMC-PL) are obtained from OSMC, either from the above
* address, from the URLs:
* http://www.openmodelica.org or
* https://github.com/OpenModelica/ or
* http://www.ida.liu.se/projects/OpenModelica,
* and in the OpenModelica distribution.
*
* GNU AGPL version 3 is obtained from:
* https://www.gnu.org/licenses/licenses.html#GPL
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

import * as fs from 'fs';
import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, getDocPath, activate } from './helper';

suite('onHover information', async () => {
test('Step', async () => {
const docUri = getDocUri('step.mo');
const position = new vscode.Position(19, 25);
const content = new vscode.MarkdownString(
fs.readFileSync(getDocPath('step.md'), 'utf-8'));
const expectedHoverInstances: vscode.Hover[] = [
new vscode.Hover(content)
];

await testOnHover(docUri, position, expectedHoverInstances);
});

test('velocityOfSound_ph', async () => {
const docUri = getDocUri('velocityOfSound_ph.mo');
const position = new vscode.Position(0, 20);
const content = new vscode.MarkdownString(
fs.readFileSync(getDocPath('velocityOfSound_ph.md'), 'utf-8'));
const expectedHoverInstances: vscode.Hover[] = [
new vscode.Hover(content)
];

await testOnHover(docUri, position, expectedHoverInstances);
});
});

async function testOnHover(
uri: vscode.Uri,
position: vscode.Position,
expectedHoverInstances: vscode.Hover[]
) {
await activate(uri);

// Execute `vscode.executeHoverProvider` to execute all hover providers
const actualHoverInstances = await vscode.commands.executeCommand<vscode.Hover[]>("vscode.executeHoverProvider", uri, position);

assertHoverInstancesEqual(expectedHoverInstances, actualHoverInstances);
}

function assertHoverInstancesEqual(expected: vscode.Hover[], actual: vscode.Hover[]) {
assert.strictEqual(expected.length, actual.length, 'Array lengths do not match.');

for (let i = 0; i < expected.length; i++) {
const expectedHover = expected[i];
const actualHover = actual[i];

let expectedContent = "";
for (let j = 0; j < expectedHover.contents.length; j++) {
const content = expectedHover.contents[j];
if (content instanceof vscode.MarkdownString) {
expectedContent += content.value;
}
}

let actualContent = "";
for (let j = 0; j < actualHover.contents.length; j++) {
const content = actualHover.contents[j];
if (content instanceof vscode.MarkdownString) {
actualContent += content.value;
}
}

assert.strictEqual(actualContent.trim(), expectedContent.trim(), `Content does not match expected content.`);
}
}
22 changes: 0 additions & 22 deletions client/src/test/symbolinformation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,9 @@ async function testSymbolInformation(
docUri,
);

//printDocumentSymbols(actualSymbolInformation);
assertDocumentSymbolsEqual(expectedDocumentSymbols, actualSymbolInformation);
}

function printDocumentSymbols(documentSymbols: vscode.DocumentSymbol[]) {
documentSymbols.forEach((symbol, index) => {
console.log(`Document Symbol ${index + 1}:`);
console.log(`Name: ${symbol.name}`);
console.log(`Kind: ${vscode.SymbolKind[symbol.kind]}`);
console.log(
`Range: ${symbol.range.start.line}:${symbol.range.start.character}, ${symbol.range.end.line}:${symbol.range.end.character}`,
);
console.log(
`SelectionRange: ${symbol.selectionRange.start.line}:${symbol.selectionRange.start.character}, ${symbol.selectionRange.end.line}:${symbol.selectionRange.end.character}`,
);
console.log('Children:');

if (symbol.children && symbol.children.length > 0) {
printDocumentSymbols(symbol.children);
}

console.log('---');
});
}

function assertDocumentSymbolsEqual(
expected: vscode.DocumentSymbol[],
actual: vscode.DocumentSymbol[],
Expand Down
7 changes: 7 additions & 0 deletions client/testFixture/MyLibrary/Examples/M.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
within MyLibrary.Examples;

model M "MWE Modelica Model"
Real x(start = 1.0, fixed = true);
equation
der(x) = -0.5*x;
end M;
4 changes: 4 additions & 0 deletions client/testFixture/MyLibrary/Examples/package.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
within MyLibrary;

package Examples
end Examples;
1 change: 1 addition & 0 deletions client/testFixture/MyLibrary/Examples/package.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
M
2 changes: 2 additions & 0 deletions client/testFixture/MyLibrary/package.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package MyLibrary "My Modelica Library"
end MyLibrary;
1 change: 1 addition & 0 deletions client/testFixture/MyLibrary/package.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Examples
20 changes: 20 additions & 0 deletions client/testFixture/step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```modelica
class Modelica_Blocks_Sources_Step "Generate step signal of type Real"
```
---

**Parameter Inputs**
```modelica
parameter input Real height = 1.0 "Height of step";
```
**Outputs**
```modelica
output Real y "Connector of Real output signal";
```

**Parameter**
```modelica
parameter input Real height = 1.0 "Height of step";
parameter Real offset = 0.0 "Offset of output signal y";
parameter Real startTime(quantity = "Time", unit = "s") = 0.0 "Output y = offset for time < startTime";
```
20 changes: 20 additions & 0 deletions client/testFixture/step.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Modelica_Blocks_Sources_Step "Generate step signal of type Real"
parameter input Real height = 1.0 "Height of step";
output Real y "Connector of Real output signal";
parameter Real offset = 0.0 "Offset of output signal y";
parameter Real startTime(quantity = "Time", unit = "s") = 0.0 "Output y = offset for time < startTime";
equation
y = offset + (if time < startTime then 0.0 else height);
annotation (
Documentation(info="<html>
<p>
The Real output y is a step signal:
</p>

<p>
<img src=\"modelica://Modelica/Resources/Images/Blocks/Sources/Step.png\"
alt=\"Step.png\">
</p>

</html>"));
end Modelica_Blocks_Sources_Step;
16 changes: 16 additions & 0 deletions client/testFixture/velocityOfSound_ph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
```modelica
function velocityOfSound_ph
```
---
**Inputs**
```modelica
input SI.Pressure p "Pressure";
input SI.SpecificEnthalpy h "Specific enthalpy";
input Integer phase = 0 "2 for two-phase, 1 for one-phase, 0 if not known";
input Integer region = 0 "If 0, region is unknown, otherwise known and this input";
```

**Outputs**
```modelica
output SI.Velocity v_sound "Speed of sound";
```
11 changes: 11 additions & 0 deletions client/testFixture/velocityOfSound_ph.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function velocityOfSound_ph
extends Modelica.Icons.Function;
input SI.Pressure p "Pressure";
input SI.SpecificEnthalpy h "Specific enthalpy";
input Integer phase = 0 "2 for two-phase, 1 for one-phase, 0 if not known";
input Integer region = 0 "If 0, region is unknown, otherwise known and this input";
output SI.Velocity v_sound "Speed of sound";
algorithm
v_sound := velocityOfSound_props_ph(p, h, waterBaseProp_ph(p, h, phase, region));
annotation(Inline = true);
end velocityOfSound_ph;
Binary file added images/hover_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading