Skip to content

Commit c08c048

Browse files
committed
feat!: remove custom nodetag files setting
This setting was added to keep track of new NodeTags, but file parsing adds impact on performance and rarely used. It is a better idea to move this to configuration file. For now this setting is not removed from VS Code configuration, so not error messages will be shown. Maybe I will find another way to use this.
1 parent 2dcbb59 commit c08c048

File tree

5 files changed

+74
-97
lines changed

5 files changed

+74
-97
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,6 @@ There are 4 settings:
159159
required files (node tag files, `pg_bsd_indent` and so on). If not specified
160160
search starts from workspace root. (Next, this settings will be used as `*SrcPath*`).
161161

162-
- `postgresql-hacker-helper.nodeTagFiles` - Files with NodeTag files
163-
164-
List of paths points to files that contain NodeTags.
165-
166-
- If path is absolute - specified files will be used directly.
167-
- If path is relative, search starts from source files directory (see
168-
`postgresql-hacker-helper.srcPath`).
169-
- If not specified, `*SrcPath*/src/include/nodes/nodes.h`
170-
and `*SrcPath*/src/include/nodes/nodetags.h` will be used.
171-
172162
- `postgresql-hacker-helper.pg_bsd_indentPath` - Path to `pg_bsd_indent`
173163

174164
Path to `pg_bsd_indent` tool. Required for formatting support. Use it if you have `pg_bsd_indent` installed globally or want to use specific version.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@
179179
"title": "Files with NodeTags",
180180
"type": "array",
181181
"default": null,
182-
"description": "Files, where NodeTag values defined. It will be used to check if variable can have NodeTag.\nCan be either relative or absolute path. Relative paths will be applied with base path of `srcPath` setting"
182+
"description": "Files, where NodeTag values defined. It will be used to check if variable can have NodeTag.\nCan be either relative or absolute path. Relative paths will be applied with base path of `srcPath` setting",
183+
"deprecationMessage": "This is not used any more due to significant performance impact.\nPlease, use \"nodetags\" parameter in extension's configuration file."
183184
},
184185
"postgresql-hacker-helper.logLevel": {
185186
"title": "Log level",

src/configuration.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface VariablesConfiguration {
1818
simpleHashTableTypes?: vars.SimplehashEntryInfo[];
1919
/* Enum values for integer fields */
2020
bitmaskEnumMembers?: vars.BitmaskMemberInfo[];
21+
/* Extra NodeTags */
22+
nodetags?: string[];
2123
}
2224

2325
export interface PgindentConfiguration {
@@ -456,6 +458,32 @@ export function parseVariablesConfiguration(configFile: unknown): VariablesConfi
456458

457459
return members;
458460
};
461+
462+
const parseNodeTags = (obj: unknown): string[] | undefined => {
463+
if (!Array.isArray(obj)) {
464+
return;
465+
}
466+
467+
const result: string[] = [];
468+
for (let o of obj) {
469+
if (typeof o !== 'string') {
470+
continue;
471+
}
472+
473+
if (o.startsWith('T_')) {
474+
o = o.substring(2);
475+
}
476+
477+
o = o.trim();
478+
if (!utils.isValidIdentifier(o)) {
479+
continue;
480+
}
481+
482+
result.push(o);
483+
}
484+
485+
return result;
486+
};
459487

460488
if (!(typeof configFile === 'object' && configFile)) {
461489
return;
@@ -487,20 +515,25 @@ export function parseVariablesConfiguration(configFile: unknown): VariablesConfi
487515
const bitmaskEnumMembers = 'enums' in configFile
488516
? parseEnumBitmasks(configFile.enums)
489517
: undefined;
518+
const nodetags = 'nodetags' in configFile
519+
? parseNodeTags(configFile.nodetags)
520+
: undefined;
490521

491522
if ( arrayInfos?.length
492523
|| aliasInfos?.length
493524
|| customListTypes?.length
494525
|| htabTypes?.length
495526
|| simpleHashTableTypes?.length
496-
|| bitmaskEnumMembers?.length) {
527+
|| bitmaskEnumMembers?.length
528+
|| nodetags?.length) {
497529
return {
498530
arrayInfos,
499531
aliasInfos,
500532
customListTypes,
501533
htabTypes,
502534
simpleHashTableTypes,
503535
bitmaskEnumMembers,
536+
nodetags,
504537
};
505538
}
506539
}

src/extension.ts

Lines changed: 26 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -496,35 +496,45 @@ export function setupExtension(context: vscode.ExtensionContext) {
496496
/* Variables view */
497497
const pgvars = setupPgVariablesView(context);
498498

499-
/* Completion support for postgresql.conf */
500-
setupPgConfSupport(context);
501-
502-
/* Setup debugger specific function */
503-
dbg.setupDebugger(context, pgvars);
504-
505499
/* Formatter */
506500
setupFormatting();
507-
501+
502+
/* Completion support for postgresql.conf */
503+
setupPgConfSupport(context);
504+
508505
/* Miscellaneous (remaining) commands */
509506
registerCommands(context, pgvars);
510507
}
511508

512509
function setupPgVariablesView(context: vscode.ExtensionContext) {
513510
const pgvars = createPgVariablesView(context);
514511

515-
/* TODO: unused - remove */
516-
const nodeVars = new vars.NodeVarRegistry();
517-
setupNodeTagFiles(context, nodeVars);
512+
/* Setup debugger specific function */
513+
dbg.setupDebugger(context, pgvars);
518514

519515
return pgvars;
520516
}
521517

522518
function setupConfigurationFile(context: vscode.ExtensionContext) {
523519
/* Mark configuration dirty when user changes it - no eager parsing */
524-
const configFileWatcher = vscode.workspace.createFileSystemWatcher(Configuration.ExtensionSettingsFileName, false, false, true);
525-
context.subscriptions.push(configFileWatcher);
526-
configFileWatcher.onDidChange(markConfigFileDirty, undefined, context.subscriptions);
527-
configFileWatcher.onDidCreate(markConfigFileDirty, undefined, context.subscriptions);
520+
const registerFolderWatcher = (folder: vscode.WorkspaceFolder) => {
521+
const pattern = new vscode.RelativePattern(
522+
folder, `.vscode/${Configuration.ExtensionSettingsFileName}`);
523+
const configFileWatcher = vscode.workspace.createFileSystemWatcher(
524+
pattern, false, false, false);
525+
context.subscriptions.push(configFileWatcher);
526+
configFileWatcher.onDidChange(markConfigFileDirty, undefined, context.subscriptions);
527+
configFileWatcher.onDidCreate(markConfigFileDirty, undefined, context.subscriptions);
528+
configFileWatcher.onDidDelete(markConfigFileDirty, undefined, context.subscriptions);
529+
};
530+
531+
if (vscode.workspace.workspaceFolders?.length) {
532+
vscode.workspace.workspaceFolders.forEach(registerFolderWatcher);
533+
} else {
534+
vscode.workspace.onDidChangeWorkspaceFolders(e => {
535+
e.added.forEach(registerFolderWatcher);
536+
}, undefined, context.subscriptions);
537+
}
528538
}
529539

530540
function registerCommands(context: vscode.ExtensionContext, pgvars: vars.PgVariablesViewProvider) {
@@ -627,6 +637,7 @@ function registerCommands(context: vscode.ExtensionContext, pgvars: vars.PgVaria
627637
simplehash: [],
628638
enums: [],
629639
typedefs: [],
640+
nodetags: [],
630641
},
631642
undefined, ' '));
632643
} catch (err: unknown) {
@@ -719,77 +730,7 @@ function registerCommands(context: vscode.ExtensionContext, pgvars: vars.PgVaria
719730
registerCommand(Configuration.Commands.FindCustomTypedefsLists, findCustomTypedefsListCmd);
720731
}
721732

722-
async function setupNodeTagFiles(context: vscode.ExtensionContext,
723-
nodeVars: vars.NodeVarRegistry) {
724-
/* TODO: remove this thing with setting */
725-
const getNodeTagFiles = () => {
726-
/* TODO: remove this setting */
727-
const customNodeTagFiles = Configuration.getCustomNodeTagFiles();
728-
if (customNodeTagFiles?.length) {
729-
return customNodeTagFiles;
730-
}
731-
732-
return [
733-
/* TODO: use getWorkspacePgSrcFile */
734-
utils.getPgSrcFile('src', 'include', 'nodes', 'nodes.h'),
735-
utils.getPgSrcFile('src', 'include', 'nodes', 'nodetags.h'),
736-
];
737-
};
738-
739-
const handleNodeTagFile = async (path: vscode.Uri) => {
740-
if (!await utils.fileExists(path)) {
741-
return;
742-
}
743-
744-
logger.debug('processing %s NodeTags file', path.fsPath);
745-
const document = await vscode.workspace.openTextDocument(path);
746-
try {
747-
const added = nodeVars.updateNodeTypesFromFile(document);
748-
logger.debug('added %i NodeTags from %s file', added, path.fsPath);
749-
} catch (err: unknown) {
750-
logger.error('could not initialize node tags array', err);
751-
}
752-
};
753-
754-
const setupSingleFolder = async (folder: vscode.WorkspaceFolder) => {
755-
const nodeTagFiles = getNodeTagFiles();
756-
757-
for (const filePath of nodeTagFiles) {
758-
const file = utils.joinPath(folder.uri, filePath);
759-
await handleNodeTagFile(file);
760-
const pattern = new vscode.RelativePattern(folder, filePath);
761-
const watcher = vscode.workspace.createFileSystemWatcher(pattern,
762-
false, false,
763-
/* ignoreDeleteEvents */ true);
764-
watcher.onDidChange(async uri => {
765-
logger.info('detected change in NodeTag file: %s', uri);
766-
await handleNodeTagFile(uri);
767-
}, context.subscriptions);
768-
watcher.onDidCreate(async uri => {
769-
logger.info('detected creation of NodeTag file: %s', uri);
770-
await handleNodeTagFile(uri);
771-
}, context.subscriptions);
772-
773-
context.subscriptions.push(watcher);
774-
}
775-
};
776-
777-
if (vscode.workspace.workspaceFolders?.length) {
778-
/* TODO: throttle */
779-
await Promise.all(
780-
vscode.workspace.workspaceFolders.map(async folder =>
781-
await setupSingleFolder(folder),
782-
),
783-
);
784-
}
785-
786-
vscode.workspace.onDidChangeWorkspaceFolders(async e => {
787-
for (const folder of e.added) {
788-
await setupSingleFolder(folder);
789-
}
790-
}, undefined, context.subscriptions);
791-
}
792-
733+
/* TODO: move to configuration.ts */
793734
export class Configuration {
794735
static ExtensionName = 'postgresql-hacker-helper';
795736
static ExtensionPrettyName = 'PostgreSQL Hacker Helper';

src/variables.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,6 +5485,18 @@ export class PgVariablesViewProvider implements vscode.TreeDataProvider<Variable
54855485
logger.error('error occurred during adding enum bitmask types', e);
54865486
}
54875487
}
5488+
5489+
if (config.nodetags?.length) {
5490+
logger.debug('adding %i custom NodeTags');
5491+
try {
5492+
/* TODO: add command to parse NodeTag files and find custom */
5493+
for (const tag of config.nodetags) {
5494+
context.nodeVarRegistry.nodeTags.add(tag);
5495+
}
5496+
} catch (err) {
5497+
logger.error('could not add custom NodeTags', err);
5498+
}
5499+
}
54885500
}
54895501

54905502
async tryGetPgVersion(frameId: number) {

0 commit comments

Comments
 (0)