Skip to content

Commit 2e45dcd

Browse files
Merge pull request #2777 from github/robertbrignull/model-remove-disableAutoNameExtensionPack
Remove the disableAutoNameExtensionPack feature flag
2 parents 4b93d34 + e9a2028 commit 2e45dcd

File tree

6 files changed

+47
-714
lines changed

6 files changed

+47
-714
lines changed

extensions/ql-vscode/src/config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,20 +707,12 @@ export function showQueriesPanel(): boolean {
707707

708708
const MODEL_SETTING = new Setting("model", ROOT_SETTING);
709709
const LLM_GENERATION = new Setting("llmGeneration", MODEL_SETTING);
710-
const DISABLE_AUTO_NAME_EXTENSION_PACK = new Setting(
711-
"disableAutoNameExtensionPack",
712-
MODEL_SETTING,
713-
);
714710
const EXTENSIONS_DIRECTORY = new Setting("extensionsDirectory", MODEL_SETTING);
715711

716712
export function showLlmGeneration(): boolean {
717713
return !!LLM_GENERATION.getValue<boolean>();
718714
}
719715

720-
export function disableAutoNameExtensionPack(): boolean {
721-
return !!DISABLE_AUTO_NAME_EXTENSION_PACK.getValue<boolean>();
722-
}
723-
724716
export function getExtensionsDirectory(languageId: string): string | undefined {
725717
return EXTENSIONS_DIRECTORY.getValue<string>({
726718
languageId,

extensions/ql-vscode/src/model-editor/extension-pack-picker.ts

Lines changed: 13 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
import { join } from "path";
22
import { outputFile, pathExists, readFile } from "fs-extra";
33
import { dump as dumpYaml, load as loadYaml } from "js-yaml";
4-
import { CancellationToken, Uri, window } from "vscode";
5-
import { CodeQLCliServer, QlpacksInfo } from "../codeql-cli/cli";
4+
import { Uri } from "vscode";
5+
import { CodeQLCliServer } from "../codeql-cli/cli";
66
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
77
import { ProgressCallback } from "../common/vscode/progress";
88
import { DatabaseItem } from "../databases/local-databases";
99
import { getQlPackPath, QLPACK_FILENAMES } from "../common/ql";
1010
import { getErrorMessage } from "../common/helpers-pure";
1111
import { ExtensionPack } from "./shared/extension-pack";
1212
import { NotificationLogger, showAndLogErrorMessage } from "../common/logging";
13-
import {
14-
disableAutoNameExtensionPack,
15-
getExtensionsDirectory,
16-
} from "../config";
13+
import { getExtensionsDirectory } from "../config";
1714
import {
1815
autoNameExtensionPack,
1916
ExtensionPackName,
2017
formatPackName,
21-
parsePackName,
22-
validatePackName,
2318
} from "./extension-pack-name";
24-
import {
25-
askForWorkspaceFolder,
26-
autoPickExtensionsDirectory,
27-
} from "./extensions-workspace-folder";
19+
import { autoPickExtensionsDirectory } from "./extensions-workspace-folder";
2820

2921
const maxStep = 3;
3022

@@ -33,7 +25,6 @@ export async function pickExtensionPack(
3325
databaseItem: Pick<DatabaseItem, "name" | "language">,
3426
logger: NotificationLogger,
3527
progress: ProgressCallback,
36-
token: CancellationToken,
3728
): Promise<ExtensionPack | undefined> {
3829
progress({
3930
message: "Resolving extension packs...",
@@ -52,182 +43,14 @@ export async function pickExtensionPack(
5243
true,
5344
);
5445

55-
if (!disableAutoNameExtensionPack()) {
56-
progress({
57-
message: "Creating extension pack...",
58-
step: 2,
59-
maxStep,
60-
});
61-
62-
return autoCreateExtensionPack(
63-
databaseItem.name,
64-
databaseItem.language,
65-
extensionPacksInfo,
66-
logger,
67-
);
68-
}
69-
70-
if (Object.keys(extensionPacksInfo).length === 0) {
71-
return pickNewExtensionPack(databaseItem, token);
72-
}
73-
74-
const extensionPacks = (
75-
await Promise.all(
76-
Object.entries(extensionPacksInfo).map(async ([name, paths]) => {
77-
if (paths.length !== 1) {
78-
void showAndLogErrorMessage(
79-
logger,
80-
`Extension pack ${name} resolves to multiple paths`,
81-
{
82-
fullMessage: `Extension pack ${name} resolves to multiple paths: ${paths.join(
83-
", ",
84-
)}`,
85-
},
86-
);
87-
88-
return undefined;
89-
}
90-
91-
const path = paths[0];
92-
93-
let extensionPack: ExtensionPack;
94-
try {
95-
extensionPack = await readExtensionPack(path, databaseItem.language);
96-
} catch (e: unknown) {
97-
void showAndLogErrorMessage(
98-
logger,
99-
`Could not read extension pack ${name}`,
100-
{
101-
fullMessage: `Could not read extension pack ${name} at ${path}: ${getErrorMessage(
102-
e,
103-
)}`,
104-
},
105-
);
106-
107-
return undefined;
108-
}
109-
110-
return extensionPack;
111-
}),
112-
)
113-
).filter((info): info is ExtensionPack => info !== undefined);
114-
115-
const extensionPacksForLanguage = extensionPacks.filter(
116-
(pack) =>
117-
pack.extensionTargets[`codeql/${databaseItem.language}-all`] !==
118-
undefined,
119-
);
120-
121-
const options: Array<{
122-
label: string;
123-
description: string | undefined;
124-
detail: string | undefined;
125-
extensionPack: ExtensionPack | null;
126-
}> = extensionPacksForLanguage.map((pack) => ({
127-
label: pack.name,
128-
description: pack.version,
129-
detail: pack.path,
130-
extensionPack: pack,
131-
}));
132-
options.push({
133-
label: "Create new extension pack",
134-
description: undefined,
135-
detail: undefined,
136-
extensionPack: null,
137-
});
138-
13946
progress({
140-
message: "Choosing extension pack...",
47+
message: "Creating extension pack...",
14148
step: 2,
14249
maxStep,
14350
});
14451

145-
const extensionPackOption = await window.showQuickPick(
146-
options,
147-
{
148-
title: "Select extension pack to use",
149-
},
150-
token,
151-
);
152-
if (!extensionPackOption) {
153-
return undefined;
154-
}
155-
156-
if (!extensionPackOption.extensionPack) {
157-
return pickNewExtensionPack(databaseItem, token);
158-
}
159-
160-
return extensionPackOption.extensionPack;
161-
}
162-
163-
async function pickNewExtensionPack(
164-
databaseItem: Pick<DatabaseItem, "name" | "language">,
165-
token: CancellationToken,
166-
): Promise<ExtensionPack | undefined> {
167-
const workspaceFolder = await askForWorkspaceFolder();
168-
if (!workspaceFolder) {
169-
return undefined;
170-
}
171-
172-
const examplePackName = autoNameExtensionPack(
173-
databaseItem.name,
174-
databaseItem.language,
175-
);
176-
177-
const name = await window.showInputBox(
178-
{
179-
title: "Create new extension pack",
180-
prompt: "Enter name of extension pack",
181-
placeHolder: examplePackName
182-
? `e.g. ${formatPackName(examplePackName)}`
183-
: "",
184-
validateInput: async (value: string): Promise<string | undefined> => {
185-
const message = validatePackName(value);
186-
if (message) {
187-
return message;
188-
}
189-
190-
const packName = parsePackName(value);
191-
if (!packName) {
192-
return "Invalid pack name";
193-
}
194-
195-
const packPath = join(workspaceFolder.uri.fsPath, packName.name);
196-
if (await pathExists(packPath)) {
197-
return `A pack already exists at ${packPath}`;
198-
}
199-
200-
return undefined;
201-
},
202-
},
203-
token,
204-
);
205-
if (!name) {
206-
return undefined;
207-
}
208-
209-
const packName = parsePackName(name);
210-
if (!packName) {
211-
return undefined;
212-
}
213-
214-
const packPath = join(workspaceFolder.uri.fsPath, packName.name);
215-
216-
if (await pathExists(packPath)) {
217-
return undefined;
218-
}
219-
220-
return writeExtensionPack(packPath, packName, databaseItem.language);
221-
}
222-
223-
async function autoCreateExtensionPack(
224-
name: string,
225-
language: string,
226-
extensionPacksInfo: QlpacksInfo,
227-
logger: NotificationLogger,
228-
): Promise<ExtensionPack | undefined> {
22952
// Get the `codeQL.model.extensionsDirectory` setting for the language
230-
const userExtensionsDirectory = getExtensionsDirectory(language);
53+
const userExtensionsDirectory = getExtensionsDirectory(databaseItem.language);
23154

23255
// If the setting is not set, automatically pick a suitable directory
23356
const extensionsDirectory = userExtensionsDirectory
@@ -239,11 +62,14 @@ async function autoCreateExtensionPack(
23962
}
24063

24164
// Generate the name of the extension pack
242-
const packName = autoNameExtensionPack(name, language);
65+
const packName = autoNameExtensionPack(
66+
databaseItem.name,
67+
databaseItem.language,
68+
);
24369
if (!packName) {
24470
void showAndLogErrorMessage(
24571
logger,
246-
`Could not automatically name extension pack for database ${name}`,
72+
`Could not automatically name extension pack for database ${databaseItem.name}`,
24773
);
24874

24975
return undefined;
@@ -259,7 +85,7 @@ async function autoCreateExtensionPack(
25985
try {
26086
extensionPack = await readExtensionPack(
26187
existingExtensionPackPaths[0],
262-
language,
88+
databaseItem.language,
26389
);
26490
} catch (e: unknown) {
26591
void showAndLogErrorMessage(
@@ -309,7 +135,7 @@ async function autoCreateExtensionPack(
309135
return undefined;
310136
}
311137

312-
return writeExtensionPack(packPath, packName, language);
138+
return writeExtensionPack(packPath, packName, databaseItem.language);
313139
}
314140

315141
async function writeExtensionPack(

extensions/ql-vscode/src/model-editor/extensions-workspace-folder.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FileType, Uri, window, workspace, WorkspaceFolder } from "vscode";
1+
import { FileType, Uri, workspace, WorkspaceFolder } from "vscode";
22
import { getOnDiskWorkspaceFoldersObjects } from "../common/vscode/workspace-folders";
33
import { extLogger } from "../common/logging/vscode";
44
import { tmpdir } from "../common/files";
@@ -200,25 +200,3 @@ export async function autoPickExtensionsDirectory(): Promise<Uri | undefined> {
200200

201201
return extensionsUri;
202202
}
203-
204-
export async function askForWorkspaceFolder(): Promise<
205-
WorkspaceFolder | undefined
206-
> {
207-
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
208-
const workspaceFolderOptions = workspaceFolders.map((folder) => ({
209-
label: folder.name,
210-
detail: folder.uri.fsPath,
211-
folder,
212-
}));
213-
214-
// We're not using window.showWorkspaceFolderPick because that also includes the database source folders while
215-
// we only want to include on-disk workspace folders.
216-
const workspaceFolder = await window.showQuickPick(workspaceFolderOptions, {
217-
title: "Select workspace folder to create extension pack in",
218-
});
219-
if (!workspaceFolder) {
220-
return undefined;
221-
}
222-
223-
return workspaceFolder.folder;
224-
}

extensions/ql-vscode/src/model-editor/model-editor-module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class ModelEditorModule extends DisposableObject {
101101
}
102102

103103
return withProgress(
104-
async (progress, token) => {
104+
async (progress) => {
105105
if (!(await this.cliServer.cliConstraints.supportsQlpacksKind())) {
106106
void showAndLogErrorMessage(
107107
this.app.logger,
@@ -125,7 +125,6 @@ export class ModelEditorModule extends DisposableObject {
125125
db,
126126
this.app.logger,
127127
progress,
128-
token,
129128
);
130129
if (!modelFile) {
131130
return;

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ export class ModelEditorView extends AbstractWebview<
483483
addedDatabase,
484484
this.app.logger,
485485
progress,
486-
token,
487486
);
488487
if (!modelFile) {
489488
return;

0 commit comments

Comments
 (0)