- Hover provider showing entity information and type - Go-to-definition (F12) for entity references - Basic IFC file validation (ISO-10303-21 header check) - Entity parsing with regex-based detection - Proper CommonJS module system (avoiding ES module issues) This replaces the broken baseline from ifc-developer-tools which had: - Non-functional ES module configuration - Circular dependency issues - Parser crashes - Non-working PositionVisitor Built on Microsoft's LSP example template for a clean, maintainable foundation. Next: Add hierarchical entity dependency tree in hover tooltip."
99 lines
5.4 KiB
JavaScript
99 lines
5.4 KiB
JavaScript
"use strict";
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
* ------------------------------------------------------------------------------------------ */
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.CodeActionFeature = void 0;
|
|
const vscode_1 = require("vscode");
|
|
const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol");
|
|
const UUID = require("./utils/uuid");
|
|
const features_1 = require("./features");
|
|
class CodeActionFeature extends features_1.TextDocumentLanguageFeature {
|
|
constructor(client) {
|
|
super(client, vscode_languageserver_protocol_1.CodeActionRequest.type);
|
|
}
|
|
fillClientCapabilities(capabilities) {
|
|
const cap = (0, features_1.ensure)((0, features_1.ensure)(capabilities, 'textDocument'), 'codeAction');
|
|
cap.dynamicRegistration = true;
|
|
cap.isPreferredSupport = true;
|
|
cap.disabledSupport = true;
|
|
cap.dataSupport = true;
|
|
// We can only resolve the edit property.
|
|
cap.resolveSupport = {
|
|
properties: ['edit']
|
|
};
|
|
cap.codeActionLiteralSupport = {
|
|
codeActionKind: {
|
|
valueSet: [
|
|
vscode_languageserver_protocol_1.CodeActionKind.Empty,
|
|
vscode_languageserver_protocol_1.CodeActionKind.QuickFix,
|
|
vscode_languageserver_protocol_1.CodeActionKind.Refactor,
|
|
vscode_languageserver_protocol_1.CodeActionKind.RefactorExtract,
|
|
vscode_languageserver_protocol_1.CodeActionKind.RefactorInline,
|
|
vscode_languageserver_protocol_1.CodeActionKind.RefactorRewrite,
|
|
vscode_languageserver_protocol_1.CodeActionKind.Source,
|
|
vscode_languageserver_protocol_1.CodeActionKind.SourceOrganizeImports
|
|
]
|
|
}
|
|
};
|
|
cap.honorsChangeAnnotations = true;
|
|
}
|
|
initialize(capabilities, documentSelector) {
|
|
const options = this.getRegistrationOptions(documentSelector, capabilities.codeActionProvider);
|
|
if (!options) {
|
|
return;
|
|
}
|
|
this.register({ id: UUID.generateUuid(), registerOptions: options });
|
|
}
|
|
registerLanguageProvider(options) {
|
|
const selector = options.documentSelector;
|
|
const provider = {
|
|
provideCodeActions: (document, range, context, token) => {
|
|
const client = this._client;
|
|
const _provideCodeActions = async (document, range, context, token) => {
|
|
const params = {
|
|
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
|
|
range: client.code2ProtocolConverter.asRange(range),
|
|
context: client.code2ProtocolConverter.asCodeActionContextSync(context)
|
|
};
|
|
return client.sendRequest(vscode_languageserver_protocol_1.CodeActionRequest.type, params, token).then((values) => {
|
|
if (token.isCancellationRequested || values === null || values === undefined) {
|
|
return null;
|
|
}
|
|
return client.protocol2CodeConverter.asCodeActionResult(values, token);
|
|
}, (error) => {
|
|
return client.handleFailedRequest(vscode_languageserver_protocol_1.CodeActionRequest.type, token, error, null);
|
|
});
|
|
};
|
|
const middleware = client.middleware;
|
|
return middleware.provideCodeActions
|
|
? middleware.provideCodeActions(document, range, context, token, _provideCodeActions)
|
|
: _provideCodeActions(document, range, context, token);
|
|
},
|
|
resolveCodeAction: options.resolveProvider
|
|
? (item, token) => {
|
|
const client = this._client;
|
|
const middleware = this._client.middleware;
|
|
const resolveCodeAction = async (item, token) => {
|
|
return client.sendRequest(vscode_languageserver_protocol_1.CodeActionResolveRequest.type, client.code2ProtocolConverter.asCodeActionSync(item), token).then((result) => {
|
|
if (token.isCancellationRequested) {
|
|
return item;
|
|
}
|
|
return client.protocol2CodeConverter.asCodeAction(result, token);
|
|
}, (error) => {
|
|
return client.handleFailedRequest(vscode_languageserver_protocol_1.CodeActionResolveRequest.type, token, error, item);
|
|
});
|
|
};
|
|
return middleware.resolveCodeAction
|
|
? middleware.resolveCodeAction(item, token, resolveCodeAction)
|
|
: resolveCodeAction(item, token);
|
|
}
|
|
: undefined
|
|
};
|
|
return [vscode_1.languages.registerCodeActionsProvider(this._client.protocol2CodeConverter.asDocumentSelector(selector), provider, (options.codeActionKinds
|
|
? { providedCodeActionKinds: this._client.protocol2CodeConverter.asCodeActionKinds(options.codeActionKinds) }
|
|
: undefined)), provider];
|
|
}
|
|
}
|
|
exports.CodeActionFeature = CodeActionFeature;
|