drccrd commented on code in PR #3717: URL: https://github.com/apache/incubator-kie-tools/pull/3717#discussion_r3805966490
########## packages/drl-vscode-extension/src/fileGrouping.ts: ########## @@ -0,0 +1,355 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import * as vscode from "vscode"; +import { LanguageClient } from "vscode-languageclient/node"; + +/** + * Shows which group of DRL files the open document compiles with, and lets the + * user pin it to a different one. + * + * The group map comes from the server (`drools/fileGroups`) rather than being + * re-derived here. The server already reads kmodule descriptors, the + * `drl-lsp-kbases.json` config and any manifests it adopts; parsing those a + * second time in the client would only create a second thing to keep correct. + */ + +type Logger = { + info: (msg: string) => void; + error: (msg: string) => void; +}; + +/** + * One group as the server reports it. `kind` is set only when the server can be + * more specific than "group" — "KIE base" for a group read from a kmodule.xml — + * so a project that never declared a kmodule is never shown kmodule vocabulary. + */ +type FileGroup = { + /** Normalized paths, for membership tests. */ + files: string[]; + kind?: string; + /** The file that declared the group, for answering "why is this file here?". */ + declaredIn?: string; +}; + +/** Group name to what the server last reported for it. */ +let groups = new Map<string, FileGroup>(); +/** Document fsPath to the group the user pinned it to. Persisted per workspace. */ +let overrides = new Map<string, string>(); +let statusItem: vscode.StatusBarItem | undefined; +let log: Logger = { info: () => undefined, error: () => undefined }; + +const OVERRIDES_STATE_KEY = "drools.fileGroupOverrides"; +const CONFIG_FILE_GLOB = "**/{drl-lsp-kbases.json,kmodule.xml}"; +const GROUPING_SETTING = "drools.lsp.grouping"; + +/** + * The `drools.lsp.grouping` setting, or undefined when unset or empty. Sent to + * the server as an object rather than a JSON string, so it arrives as structured + * JSON instead of a quoted, escaped string. + */ +export function groupingSetting(): object | undefined { + const value = vscode.workspace.getConfiguration().get<object>(GROUPING_SETTING); + return !value || Object.keys(value).length === 0 ? undefined : value; +} + +/** Files the grouping layer needs to know about. */ +const WORKSPACE_FILE_GLOB = "**/{*.drl,kmodule.xml,drl-lsp-kbases.json}"; + +/** + * Enumerates the workspace files the server should consider, as URIs. + * + * The client does this rather than the server walking the filesystem, because + * `findFiles` already applies the user's `files.exclude`, `search.exclude` and + * ignore files. A server-side walk can only approximate that with a hardcoded + * list of directory names to skip, which goes stale and silently drops files. + */ +export async function enumerateWorkspaceFiles(): Promise<string[]> { + if (!vscode.workspace.workspaceFolders?.length) { + return []; + } + const found = await vscode.workspace.findFiles(WORKSPACE_FILE_GLOB); + return found.map((uri) => uri.toString()); +} + +function normalize(p: string): string { + return p.replace(/\\/g, "/").toLowerCase(); +} Review Comment: I'm not sure if defining rules files with the same names and different casing is a nomenclature that should be expected to be supported... but the fix is minor. Fixed in 857b02068548f474d28ddc4f05ddecce2a62b75a -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
