Skip to content
Open
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
22 changes: 22 additions & 0 deletions client/out/extension.js

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

2 changes: 1 addition & 1 deletion client/out/extension.js.map

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

48 changes: 30 additions & 18 deletions client/package-lock.json

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

30 changes: 29 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import * as path from "path";
import { commands, ExtensionContext, window, workspace } from "vscode";
import { commands, ExtensionContext, extensions, workspace } from "vscode";
import {
LanguageClient,
LanguageClientOptions,
NotificationType,
ServerOptions,
TransportKind,
} from "vscode-languageclient/node";
import { generateQmlFile } from "./commands/generateQmlFile";
import { organizeImports } from './commands/organizeImports';
import { glob } from 'glob';

const QmlTypesNotification = {
type: new NotificationType<string[]>('qml/types')
};

let client: LanguageClient;

Expand Down Expand Up @@ -64,4 +70,26 @@ function serverConnect(context: ExtensionContext) {
);

client.start();
client.onReady().then(() => {
const qmlTypes = getQmlTypes();
client.sendNotification(QmlTypesNotification.type, qmlTypes);
});
}

function getQmlTypes(): string[] {
return extensions.all.flatMap(extension => {
const qmlTypes = extension.packageJSON?.contributes?.qmlTypes;

if (!Array.isArray(qmlTypes)) {
return [];
}

return qmlTypes.flatMap(pattern =>
glob.sync(pattern, {
absolute: true,
cwd: extension.extensionPath,
nodir: true
})
);
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"url": "https://github.com/AndreOneti/qml-formatter/issues"
},
"contributes": {
"qmlTypes": [],
"languages": [
{
"id": "qml",
Expand Down
25 changes: 25 additions & 0 deletions server/out/server.js

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

2 changes: 1 addition & 1 deletion server/out/server.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
InitializeParams,
InitializeResult,
Location,
NotificationType,
Position,
ProposedFeatures,
TextDocumentChangeEvent,
Expand All @@ -35,6 +36,10 @@ import { Formatter } from "./formatter";
import References from "./types";
import "./utils/prototypes";

const QmlTypesNotification = {
type: new NotificationType<string[]>('qml/types')
};

class ServiceDispatcher {
private connection = createConnection(ProposedFeatures.all);
private documents: TextDocuments<TextDocument> = new TextDocuments(
Expand Down Expand Up @@ -88,6 +93,10 @@ class ServiceDispatcher {
this.onCodeAction(params)
);

this.connection.onNotification(QmlTypesNotification.type, uris => {
this.onQmlTypesNotification(uris);
});

// this.connection.onDocumentSymbol(handler => this.onDocumentSymbol(handler));
// this.connection.onWorkspaceSymbol(handler => this.onWorkspaceSymbol(handler));
// this.connection.onDidChangeConfiguration(change => this.onDidChangeConfiguration(change));
Expand Down Expand Up @@ -935,6 +944,22 @@ class ServiceDispatcher {
return actions;
}

private onQmlTypesNotification(uris: string[]): void {
uris.forEach(uri => {
try {
const jsonString = fs.readFileSync(uri, 'utf-8');
const qmlTypes = JSON.parse(jsonString);
if (qmlTypes !== null && typeof qmlTypes === 'object') {
for (const name in qmlTypes) {
References[name] = qmlTypes[name];
}
}
} catch (err) {
console.error(err);
}
});
}

private createImport(document: TextDocument, data: string): CodeAction {
const textEdit: TextEdit[] = [];

Expand Down