Skip to content
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
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/gotoDeclaration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/mslLibrary.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/symbolinformation.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/analysis/reference.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
34 changes: 31 additions & 3 deletions server/src/analysis/resolveReference.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down Expand Up @@ -441,12 +441,40 @@ function resolveAbsoluteReference(
logger.debug(`Resolving ${reference}`);

logger.debug(project.libraries.map((x) => x.name + ' | ' + x.path).join('\n\t'));
const library = project.libraries.find((lib) => lib.name === reference.symbols[0]);
if (library == null) {

// Multiple libraries may share the same name (e.g. a standalone file and a
// directory package with the same top-level class). Try each of them until
// one resolves the full reference chain.
const libraries = project.libraries.filter((lib) => lib.name === reference.symbols[0]);
if (libraries.length === 0) {
logger.debug(`Couldn't find library: ${reference.symbols[0]}`);
return null;
}

for (const library of libraries) {
const resolved = resolveReferenceInLibrary(library, reference);
if (resolved != null) {
logger.debug(`Resolved symbol ${resolved}`);
return resolved;
}
}

return null;
}

/**
* Attempts to resolve an absolute reference chain within a single library.
*
* @param library the library to search
* @param reference an absolute reference
* @returns a resolved reference, or `null` if the chain could not be resolved
* in this library
*/
function resolveReferenceInLibrary(
library: ModelicaLibrary,
reference: UnresolvedAbsoluteReference,
): ResolvedReference | null {

let alreadyResolved: ResolvedReference | null = null;
for (let i = 0; i < reference.symbols.length; i++) {
alreadyResolved = resolveNext(library, reference.symbols[i], alreadyResolved);
Expand Down
2 changes: 1 addition & 1 deletion server/src/analysis/test/resolveReference.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
8 changes: 2 additions & 6 deletions server/src/analyzer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class Analyzer {
// TODO: go deeper... something like `TreeSitterUtil.forEach` but for files
// would be good here
for (const nestedRelative of await fs.readdir(libraryPath)) {
const nested = path.resolve(nestedRelative);
const nested = path.resolve(libraryPath, nestedRelative);
if (!isLibrary(nested)) {
continue;
}
Expand Down Expand Up @@ -327,10 +327,6 @@ export default class Analyzer {
* Locates the first node at the given text position that matches the given
* `condition`, starting from the `rootNode`.
*
* Note: it is very important to have some kind of condition. If one tries to
* just accept the first node at that position, this function will always
* return the `rootNode` (or `undefined` if outside the node.)
*
* @param rootNode node to start searching from. parents/siblings of this node will be ignored
* @param offset the offset of the symbol from the start of the document
* @param condition the condition to check if a node is "good"
Expand Down
2 changes: 1 addition & 1 deletion server/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/project/document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
35 changes: 35 additions & 0 deletions server/src/project/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2026, 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.
*
*/

export { ModelicaDocument } from "./document";
export { ModelicaLibrary } from "./library";
export { ModelicaProject } from "./project";
8 changes: 6 additions & 2 deletions server/src/project/library.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down Expand Up @@ -44,7 +44,7 @@ export class ModelicaLibrary {
readonly #project: ModelicaProject;
readonly #documents: Map<string, ModelicaDocument>;
readonly #isWorkspace: boolean;
readonly #name: string;
#name: string;
#path: string;

public constructor(
Expand Down Expand Up @@ -110,6 +110,10 @@ export class ModelicaLibrary {
return this.#name;
}

public rename(newName: string): void {
this.#name = newName;
}

public get path(): string {
return this.#path;
}
Expand Down
11 changes: 8 additions & 3 deletions server/src/project/project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down Expand Up @@ -40,6 +40,7 @@ import path from 'node:path';
import { ModelicaLibrary } from './library';
import { ModelicaDocument } from './document';
import { logger } from '../util/logger';
import * as TreeSitterUtil from '../util/tree-sitter';

/** Options for {@link ModelicaProject.getDocument} */
export interface GetDocumentOptions {
Expand Down Expand Up @@ -139,15 +140,19 @@ export class ModelicaProject {

// If the document doesn't belong to a library, it could still be loaded
// as a standalone document if it has an empty or non-existent within clause
const standaloneName = path.basename(documentPath).split('.')[0];
const fallbackName = path.basename(documentPath).split('.')[0];
const standaloneLibrary = new ModelicaLibrary(
this,
path.dirname(documentPath),
false,
standaloneName,
fallbackName,
);
const document = await ModelicaDocument.load(this, standaloneLibrary, documentPath);
if (document.within.length === 0) {
// Use the declared class name as the library name so resolution can find it by class name.
const classNames = TreeSitterUtil.getDeclaredIdentifiers(document.tree.rootNode);
standaloneLibrary.rename(classNames[0] ?? fallbackName);
standaloneLibrary.documents.set(documentPath, document);
this.addLibrary(standaloneLibrary);
logger.debug(`Added document: ${documentPath}`);
return document;
Expand Down
2 changes: 1 addition & 1 deletion server/src/project/test/document.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/project/test/project.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/analyzer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
2 changes: 1 addition & 1 deletion server/src/util/declarations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
36 changes: 35 additions & 1 deletion server/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2026, 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 url from "node:url";
import * as LSP from "vscode-languageserver";


export const uriToPath = url.fileURLToPath;

export function pathToUri(filePath: string): LSP.URI {
Expand Down
2 changes: 1 addition & 1 deletion server/src/util/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2024, Open Source Modelica Consortium (OSMC),
* Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down
Loading
Loading