Skip to content

Commit

Permalink
qt-qml: qmlls: Add -d option to specify kit documentation path
Browse files Browse the repository at this point in the history
* Add `findQtPathsInKitDir()` to get Qt paths in kit directory
* Add `qt-qml.qmlls.customDocsPath` setting to specify kit documentation path
* Add `-d` option to specify kit documentation path
* Use `QT_INSTALL_DOCS` from `qtpaths` as default documentation path

When `qt-qml.qmlls.docsPath` is specified, it overrides the default
in either selected kit or qtpaths.
  • Loading branch information
OrkunTokdemir committed Feb 13, 2025
1 parent 766d8af commit de467db
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
12 changes: 12 additions & 0 deletions qt-lib/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ export async function waitForQtCpp() {
}
}

export function findQtPathsInKitDir(dir: string): string | undefined {
const exeNames = [`qtpaths${OSExeSuffix}`, `qtpaths6${OSExeSuffix}`];

for (const exeName of exeNames) {
const exePath = path.join(dir, 'bin', exeName);
if (fsSync.existsSync(exePath)) {
return exePath;
}
}
return undefined;
}

class FileWriter {
private readonly files = new Map<
string,
Expand Down
6 changes: 6 additions & 0 deletions qt-qml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
"description": "Specify the custom qmlls executable path",
"scope": "machine-overridable"
},
"qt-qml.qmlls.customDocsPath": {
"type": "string",
"default": "",
"description": "Specify the documentation path for qmlls",
"scope": "machine-overridable"
},
"qt-qml.qmlls.additionalImportPaths": {
"type": "array",
"items": {
Expand Down
30 changes: 29 additions & 1 deletion qt-qml/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import * as vscode from 'vscode';
import path from 'path';

import { Project, ProjectManager, createLogger } from 'qt-lib';
import {
Project,
ProjectManager,
createLogger,
findQtPathsInKitDir
} from 'qt-lib';
import { Qmlls } from '@/qmlls';
import { coreAPI } from '@/extension';

Expand Down Expand Up @@ -93,11 +98,29 @@ export class QMLProject implements Project {
this.qtpathsExe = coreAPI?.getValue<string>(this.folder, 'selectedQtPaths');
this.buildDir = coreAPI?.getValue<string>(this.folder, 'buildDir');
}
getDocsPathFromKitDir(kitDir: string) {
const qtpaths = findQtPathsInKitDir(kitDir);
if (!qtpaths) {
logger.error(`Could not find qtpaths in: ${this.kitPath}`);
return undefined;
}
const qtInfo = coreAPI?.getQtInfoFromPath(qtpaths);
if (!qtInfo) {
logger.error('Could not find qtInfo');
return undefined;
}
return qtInfo.get('QT_INSTALL_DOCS');
}

updateQmllsParams() {
this.qmlls.clearImportPaths();
if (this.kitPath) {
this.qmlls.addImportPath(path.join(this.kitPath, 'qml'));
const docsPath = this.getDocsPathFromKitDir(this.kitPath);
if (docsPath) {
logger.info('Setting docs path:', docsPath);
this.qmlls.docsPath = docsPath;
}
} else if (this.qtpathsExe) {
const info = coreAPI?.getQtInfoFromPath(this.qtpathsExe);
if (!info) {
Expand All @@ -108,6 +131,11 @@ export class QMLProject implements Project {
throw new Error('Could not find QT_INSTALL_QML');
}
this.qmlls.addImportPath(qmlImportPath);
const docsPath = info.get('QT_INSTALL_DOCS');
if (docsPath) {
logger.info('Setting docs path:', docsPath);
this.qmlls.docsPath = docsPath;
}
}
}
set buildDir(buildDir: string | undefined) {
Expand Down
21 changes: 21 additions & 0 deletions qt-qml/src/qmlls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export async function fetchAssetAndDecide(options?: {
}

export class Qmlls {
private _docsPath: string | undefined;
private readonly _disposables: vscode.Disposable[] = [];
private readonly _importPaths = new Set<string>();
private _client: LanguageClient | undefined;
Expand Down Expand Up @@ -151,6 +152,14 @@ export class Qmlls {
this._importPaths.add(importPath);
}

get docsPath() {
return this._docsPath;
}

set docsPath(docsPath: string | undefined) {
this._docsPath = docsPath;
}

removeImportPath(importPath: string) {
this._importPaths.delete(importPath);
}
Expand Down Expand Up @@ -279,6 +288,18 @@ export class Qmlls {
[]
);

let docsPath = configs.get<string>('customDocsPath', '');
if (docsPath) {
// If qt-qml.qmlls.customDocsPath is set, use it instead of the path from the kit
docsPath = untildify(docsPath);
} else {
docsPath = this.docsPath ?? '';
}

if (docsPath) {
args.push(`-d${docsPath}`);
}

const toImportParam = (p: string) => {
return `-I${p}`;
};
Expand Down

0 comments on commit de467db

Please sign in to comment.