ifc-language-server/client/node_modules/vscode-languageclient/lib/common/fileSystemWatcher.js
Ryan Schultz 8afacf268a Implemented a working Language Server Protocol (LSP) for IFC files with:
- 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."
2025-12-07 10:20:07 -06:00

95 lines
4.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.FileSystemWatcherFeature = void 0;
const vscode_1 = require("vscode");
const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol");
const features_1 = require("./features");
class FileSystemWatcherFeature {
constructor(client, notifyFileEvent) {
this._client = client;
this._notifyFileEvent = notifyFileEvent;
this._watchers = new Map();
}
getState() {
return { kind: 'workspace', id: this.registrationType.method, registrations: this._watchers.size > 0 };
}
get registrationType() {
return vscode_languageserver_protocol_1.DidChangeWatchedFilesNotification.type;
}
fillClientCapabilities(capabilities) {
(0, features_1.ensure)((0, features_1.ensure)(capabilities, 'workspace'), 'didChangeWatchedFiles').dynamicRegistration = true;
(0, features_1.ensure)((0, features_1.ensure)(capabilities, 'workspace'), 'didChangeWatchedFiles').relativePatternSupport = true;
}
initialize(_capabilities, _documentSelector) {
}
register(data) {
if (!Array.isArray(data.registerOptions.watchers)) {
return;
}
const disposables = [];
for (const watcher of data.registerOptions.watchers) {
const globPattern = this._client.protocol2CodeConverter.asGlobPattern(watcher.globPattern);
if (globPattern === undefined) {
continue;
}
let watchCreate = true, watchChange = true, watchDelete = true;
if (watcher.kind !== undefined && watcher.kind !== null) {
watchCreate = (watcher.kind & vscode_languageserver_protocol_1.WatchKind.Create) !== 0;
watchChange = (watcher.kind & vscode_languageserver_protocol_1.WatchKind.Change) !== 0;
watchDelete = (watcher.kind & vscode_languageserver_protocol_1.WatchKind.Delete) !== 0;
}
const fileSystemWatcher = vscode_1.workspace.createFileSystemWatcher(globPattern, !watchCreate, !watchChange, !watchDelete);
this.hookListeners(fileSystemWatcher, watchCreate, watchChange, watchDelete, disposables);
disposables.push(fileSystemWatcher);
}
this._watchers.set(data.id, disposables);
}
registerRaw(id, fileSystemWatchers) {
let disposables = [];
for (let fileSystemWatcher of fileSystemWatchers) {
this.hookListeners(fileSystemWatcher, true, true, true, disposables);
}
this._watchers.set(id, disposables);
}
hookListeners(fileSystemWatcher, watchCreate, watchChange, watchDelete, listeners) {
if (watchCreate) {
fileSystemWatcher.onDidCreate((resource) => this._notifyFileEvent({
uri: this._client.code2ProtocolConverter.asUri(resource),
type: vscode_languageserver_protocol_1.FileChangeType.Created
}), null, listeners);
}
if (watchChange) {
fileSystemWatcher.onDidChange((resource) => this._notifyFileEvent({
uri: this._client.code2ProtocolConverter.asUri(resource),
type: vscode_languageserver_protocol_1.FileChangeType.Changed
}), null, listeners);
}
if (watchDelete) {
fileSystemWatcher.onDidDelete((resource) => this._notifyFileEvent({
uri: this._client.code2ProtocolConverter.asUri(resource),
type: vscode_languageserver_protocol_1.FileChangeType.Deleted
}), null, listeners);
}
}
unregister(id) {
let disposables = this._watchers.get(id);
if (disposables) {
for (let disposable of disposables) {
disposable.dispose();
}
}
}
clear() {
this._watchers.forEach((disposables) => {
for (let disposable of disposables) {
disposable.dispose();
}
});
this._watchers.clear();
}
}
exports.FileSystemWatcherFeature = FileSystemWatcherFeature;