Implemented more robust LSP diagnostics and better parsing logic

This commit is contained in:
Martino Ferrari
2026-01-30 18:21:24 +01:00
parent b4d3edab9d
commit f121f7c15d
10 changed files with 422 additions and 129 deletions

View File

@@ -43,7 +43,7 @@ The brain of the system. It maintains a holistic view of the project.
* **ProjectTree**: The central data structure. It holds the root of the configuration hierarchy (`Root`), references, and isolated files.
* **ProjectNode**: Represents a logical node in the configuration. Since a node can be defined across multiple files (fragments), `ProjectNode` aggregates these fragments. It also stores locally defined variables in its `Variables` map.
* **NodeMap**: A hash map index (`map[string][]*ProjectNode`) for $O(1)$ symbol lookups, optimizing `FindNode` operations.
* **Reference Resolution**: The `ResolveReferences` method links `Reference` objects to their target `ProjectNode` or `VariableDefinition`. It uses `resolveScopedName` to respect lexical scoping rules, searching up the hierarchy from the reference's container.
* **Reference Resolution**: The `ResolveReferences` method links `Reference` objects to their target `ProjectNode` or `VariableDefinition`. It uses `ResolveName` (exported) which respects lexical scoping rules by searching the hierarchy upwards from the reference's container, using `FindNode` for deep searches within each scope.
### 3. `internal/validator`
@@ -100,12 +100,13 @@ Manages CUE schemas.
5. Diagnostics are printed (CLI) or published via `textDocument/publishDiagnostics` (LSP).
### Threading Check Logic
1. Finds the `RealTimeApplication` node.
2. Iterates through `States` and `Threads`.
3. For each Thread, resolves the `Functions` (GAMs).
4. For each GAM, resolves connected `DataSources` via Input/Output signals.
5. Maps `DataSource -> Thread` within the context of a State.
6. If a DataSource is seen in >1 Thread, it checks the `#meta.multithreaded` property. If false (default), an error is raised.
1. Iterates all `RealTimeApplication` nodes found in the project.
2. For each App:
1. Finds `States` and `Threads`.
2. For each Thread, resolves the `Functions` (GAMs).
3. For each GAM, resolves connected `DataSources` via Input/Output signals.
4. Maps `DataSource -> Thread` within the context of a State.
5. If a DataSource is seen in >1 Thread, it checks the `#meta.multithreaded` property. If false (default), an error is raised.
### INOUT Ordering Logic
1. Iterates Threads.

View File

@@ -173,9 +173,11 @@ You can define variables using `#var`. The type expression supports CUE syntax.
```
### Usage
Reference a variable using `@`:
Reference a variable using `$` (preferred) or `@`:
```marte
Field = $MyVar
// or
Field = @MyVar
```
@@ -187,7 +189,7 @@ You can use operators in field values. Supported operators:
```marte
Field1 = 10 + 20 * 2 // 50
Field2 = "Hello " .. "World"
Field3 = @MyVar + 5
Field3 = $MyVar + 5
```
### Build Override
@@ -197,3 +199,21 @@ You can override variable values during build:
mdt build -vMyVar=200 -vEnv="PROD" src/*.marte
```
## 7. Validation Rules (Detail)
### Data Flow Validation
`mdt` checks for logical data flow errors:
- **Consumed before Produced**: If a GAM reads an INOUT signal that hasn't been written by a previous GAM in the same cycle, an error is reported.
- **Produced but not Consumed**: If a GAM writes an INOUT signal that is never read by subsequent GAMs, a warning is reported.
- **Initialization**: Providing a `Value` field in an `InputSignal` treats it as "produced" (initialized), resolving "Consumed before Produced" errors.
### Threading Rules
A DataSource that is **not** marked as multithreaded (default) cannot be used by GAMs running in different threads within the same State.
To allow sharing, the DataSource class in the schema must have `#meta: multithreaded: true`.
### Implicit vs Explicit Signals
- **Explicit**: Signal defined in `DataSource.Signals`.
- **Implicit**: Signal used in GAM but not defined in DataSource. `mdt` reports a warning unless suppressed.

View File

@@ -2,11 +2,12 @@
`mdt` includes a Language Server Protocol (LSP) implementation that provides features like:
- Syntax highlighting and error reporting
- Syntax highlighting and error reporting (Parser & Semantic)
- Auto-completion
- Go to Definition / References
- Hover documentation
- Symbol renaming
- Incremental synchronization (Robust)
The LSP server is started via the command: