Skip to content

Commit 4dc843e

Browse files
Merge remote-tracking branch 'origin/develop' into develop
2 parents 70eafcc + 383ee11 commit 4dc843e

11 files changed

Lines changed: 105 additions & 104 deletions

File tree

libs/mcp/language-server-tools/src/lib/tasks/register-mcp-task-tools.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ import {
66
RegisterMCPTool_ListENVITools,
77
RegisterMCPTool_RunENVITool,
88
} from '@idl/mcp/server-tools';
9-
import { FilterMCPENVITasks, MCPTaskRegistry } from '@idl/mcp/tasks';
9+
import { MCPTaskRegistry } from '@idl/mcp/tasks';
1010
import { IDLIndex } from '@idl/parsing/index';
11-
import {
12-
GLOBAL_TOKEN_TYPES,
13-
GlobalFunctionToken,
14-
GlobalStructureToken,
15-
IGlobalIndexedToken,
16-
} from '@idl/types/idl-data-types';
11+
import { GLOBAL_TOKEN_TYPES } from '@idl/types/idl-data-types';
1712

1813
/**
1914
* Registers MCP Task tools from parsed code on IDL's search path
@@ -46,30 +41,11 @@ export async function RegisterMCPTaskTools(server: MCPServer, index: IDLIndex) {
4641
RegisterMCPTool_RunENVITool(server, registry);
4742
RegisterMCPTool_CreateENVIModelerWorkflow(server, registry);
4843

49-
/** Get all functions that we know about */
50-
const functions =
51-
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.FUNCTION];
52-
53-
/** Get all structures that we know about */
54-
const structures =
55-
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.STRUCTURE];
56-
57-
/** Find names of ENVI Tasks and exclude those we dont need to expose */
58-
const keys = FilterMCPENVITasks(functions, Object.keys(structures)).sort();
59-
60-
server.logManager.log({
61-
log: IDL_MCP_LOG,
62-
type: 'info',
63-
content: `Attempting to register ${keys.length} ENVI Tools`,
64-
});
65-
66-
// add all ENVI Tasks
67-
for (let i = 0; i < keys.length; i++) {
68-
registry.registerTask(
69-
functions[keys[i]][0] as IGlobalIndexedToken<GlobalFunctionToken>,
70-
structures[keys[i]][0] as IGlobalIndexedToken<GlobalStructureToken>,
71-
);
72-
}
44+
/** Register tasks that we have found */
45+
registry.registerTasksFromGlobalTokens(
46+
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.FUNCTION],
47+
index.globalIndex.globalTokensByTypeByName[GLOBAL_TOKEN_TYPES.STRUCTURE],
48+
);
7349

7450
// server.logManager.log({
7551
// log: IDL_MCP_LOG,

libs/mcp/server-tools/src/lib/tools/envi/register-mcp-tool-create-envi-modeler-workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function RegisterMCPTool_CreateENVIModelerWorkflow(
214214
edges as ENVIModelerEdge[],
215215
registry,
216216
);
217-
const modelContent = JSON.stringify(modelJSON, null, 4);
217+
const modelContent = JSON.stringify(modelJSON, null, 2);
218218

219219
// ---- write to disk
220220
try {

libs/mcp/tasks/src/lib/mcp-task-registry.class.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Ajv from 'ajv';
1212
import { z, ZodRawShape } from 'zod';
1313
import { zodToJsonSchema } from 'zod-to-json-schema';
1414

15+
import { FilterMCPENVITasks } from './helpers/filter-mcp-envi-tasks';
1516
import { GetCleanDescription } from './helpers/get-clean-description';
1617
import { StrictCheck } from './helpers/strict-check';
1718
import {
@@ -104,7 +105,7 @@ export class MCPTaskRegistry {
104105
/**
105106
* Gets information about a task
106107
*/
107-
getTaskDetail(taskName: string): ITaskInformation {
108+
getTaskDetail(taskName: string): ITaskInformation | undefined {
108109
/** Get lower case name */
109110
const lc = taskName.toLowerCase();
110111

@@ -138,8 +139,16 @@ export class MCPTaskRegistry {
138139
taskFunction: IGlobalIndexedToken<GlobalFunctionToken>,
139140
taskStructure: IGlobalIndexedToken<GlobalStructureToken>,
140141
) {
142+
// extract task name
143+
const match = TASK_REGEX.exec(taskStructure.meta.display);
144+
145+
// return if no match - prevent errors when we don't really have a task
146+
if (match === null) {
147+
return;
148+
}
149+
141150
/** Get task display name */
142-
const taskDisplay = TASK_REGEX.exec(taskStructure.meta.display)[1];
151+
const taskDisplay = match[1];
143152

144153
/** Determine the type of task */
145154
const toolType = taskStructure.name.startsWith('envi') ? 'ENVI' : 'IDL';
@@ -296,6 +305,32 @@ export class MCPTaskRegistry {
296305
};
297306
}
298307

308+
/**
309+
* Loads tasks from global tokens (i.e. after we index a location)
310+
*/
311+
registerTasksFromGlobalTokens(
312+
functions: {
313+
[key: string]: IGlobalIndexedToken<GlobalFunctionToken>[];
314+
},
315+
structures: {
316+
[key: string]: IGlobalIndexedToken<GlobalStructureToken>[];
317+
},
318+
) {
319+
/** Find names of ENVI Tasks and exclude those we dont need to expose */
320+
const keys = FilterMCPENVITasks(functions, Object.keys(structures)).sort();
321+
322+
this.logger.log({
323+
log: IDL_MCP_LOG,
324+
type: 'info',
325+
content: `Attempting to register ${keys.length} ENVI Tools`,
326+
});
327+
328+
// add all ENVI Tasks
329+
for (let i = 0; i < keys.length; i++) {
330+
this.registerTask(functions[keys[i]][0], structures[keys[i]][0]);
331+
}
332+
}
333+
299334
/**
300335
* Remove a task from the registry
301336
*
@@ -356,7 +391,7 @@ export class MCPTaskRegistry {
356391
// check if we have JSON schema problems
357392
if (!valid) {
358393
// Format validation errors for the response
359-
const errors = validate.errors
394+
const errors = (validate.errors || [])
360395
.map(
361396
(err) =>
362397
`- ${err.instancePath || 'root'}: ${err.message}${

libs/notebooks/shared/src/lib/parsed-idl-notebook.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { IParsed } from '@idl/types/syntax-tree';
44
* Data structure for a parsed notebook file
55
*/
66
export interface IParsedIDLNotebook {
7-
[key: string]: IParsed;
7+
[key: string]: IParsed | undefined;
88
}

libs/parsing/index/src/lib/global-index.class.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class GlobalIndex {
5656
/**
5757
* Tokens categorized by type to reduce number of checks for global conflicts
5858
*/
59-
globalTokensByTypeByName: GlobalTokensByTypeByName = {};
59+
globalTokensByTypeByName!: GlobalTokensByTypeByName;
6060

6161
/**
6262
* Constructor which initializes properties in our constants so that they
@@ -111,7 +111,7 @@ export class GlobalIndex {
111111
const byNameForType = this.globalTokensByTypeByName[types[i]];
112112
const names = Object.keys(byNameForType);
113113
for (let j = 0; j < names.length; j++) {
114-
exported[types[i]].push(byNameForType[names[j]][0]);
114+
exported[types[i]].push(byNameForType[names[j]][0] as any);
115115
}
116116
}
117117
return exported;
@@ -332,7 +332,9 @@ export class GlobalIndex {
332332
break;
333333
case byName.length === 1:
334334
// remove display name
335-
delete IDL_DISPLAY_NAMES[tokens[i].type][tokens[i].name];
335+
delete (IDL_DISPLAY_NAMES[tokens[i].type] || {})[
336+
tokens[i].name
337+
];
336338

337339
// remove structure/type names
338340
if (tokens[i].type === GLOBAL_TOKEN_TYPES.STRUCTURE) {
@@ -355,7 +357,7 @@ export class GlobalIndex {
355357

356358
// mark as changed if we had problems
357359
if (file in this.globalSyntaxProblemsByFile) {
358-
this.changedFiles[file] = undefined;
360+
this.changedFiles[file] = false;
359361
}
360362

361363
// reset problems for our file as well
@@ -456,9 +458,11 @@ export class GlobalIndex {
456458

457459
// save by type
458460
if (token.name in this.globalTokensByTypeByName[token.type]) {
459-
this.globalTokensByTypeByName[token.type][token.name].push(token);
461+
this.globalTokensByTypeByName[token.type][token.name].push(
462+
token as any,
463+
);
460464
} else {
461-
this.globalTokensByTypeByName[token.type][token.name] = [token];
465+
this.globalTokensByTypeByName[token.type][token.name] = [token as any];
462466
}
463467
}
464468
}
@@ -558,8 +562,8 @@ export class GlobalIndex {
558562

559563
// check all files that we need to process
560564
const files = this.globalTokensByTypeByName[token.type][token.name]
561-
.filter((item) => item.file !== undefined)
562-
.map((item) => item.file);
565+
.map((item) => item.file)
566+
.filter((item) => item !== undefined);
563567

564568
// process each file
565569
for (let z = 0; z < files.length; z++) {
@@ -577,6 +581,11 @@ export class GlobalIndex {
577581
// extract the problem
578582
const problem = problems[j];
579583

584+
// skip if no file
585+
if (!problem.file) {
586+
continue;
587+
}
588+
580589
// check if our file matches
581590
if (
582591
(problem.file === token.file || clear) &&

libs/parsing/index/src/lib/global-index.interface.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export type GlobalIndexedToken = IGlobalIndexedToken<GlobalTokenType>;
2222
* Lookup with all tokens by type. We store an array of the token types
2323
* which we can manually search through to find.
2424
*/
25-
export interface GlobalTokensByTypeByName {
26-
[key: string]: { [key: string]: GlobalIndexedToken[] };
27-
}
25+
export type GlobalTokensByTypeByName = {
26+
[key in GlobalTokenType]: { [name: string]: IGlobalIndexedToken<key>[] };
27+
};
2828

2929
/**
3030
* Lookup with tokens by type for easier access when we export
@@ -33,14 +33,14 @@ export type ExportedGlobalTokensByType = {
3333
[key in GlobalTokenType]: IGlobalIndexedToken<key>[];
3434
};
3535

36-
/**
37-
* For each file we index tokens for, track which types of tokens they
38-
* contribute to filter the locations we need to clean up tokens from so
39-
* we don't need to process all tokens.
40-
*/
41-
export interface ITokenTypesByFile {
42-
[file: string]: { [key: string]: GlobalIndexedToken[] };
43-
}
36+
// /**
37+
// * For each file we index tokens for, track which types of tokens they
38+
// * contribute to filter the locations we need to clean up tokens from so
39+
// * we don't need to process all tokens.
40+
// */
41+
// export type ITokenTypesByFile = {
42+
// [file: string]: { [key in GlobalTokenType]: GlobalIndexedToken[] };
43+
// };
4444

4545
/**
4646
* Maps our token types to problem codes

libs/parsing/index/src/lib/idl-index.class.ts

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class IDLIndex {
445445
// check if we have the file in our lookup
446446
if (this.parsedCache.has(file)) {
447447
const text = this.parsedCache.text(file);
448-
if (text.length > 0) {
448+
if (Array.isArray(text)) {
449449
return text.join('\n');
450450
}
451451
}
@@ -473,7 +473,7 @@ export class IDLIndex {
473473
* Check if local
474474
*/
475475
case this.parsedCache.has(file):
476-
globals = this.parsedCache.get(file).global;
476+
globals = (this.parsedCache.get(file) as IParsed).global;
477477
break;
478478

479479
default:
@@ -554,7 +554,7 @@ export class IDLIndex {
554554
IDLFileHelper.isPRODef(file)
555555
)
556556
) {
557-
return undefined;
557+
return [];
558558
}
559559

560560
// if we are multi threaded, then
@@ -881,14 +881,14 @@ export class IDLIndex {
881881
// post process cell
882882
await this.postProcessProFile(
883883
files[i],
884-
byCell[files[i]],
884+
byCell[files[i]] as IParsed,
885885
token,
886886
[],
887887
false,
888888
);
889889

890890
// update stored token
891-
this.parsedCache.add(files[i], byCell[files[i]]);
891+
this.parsedCache.add(files[i], byCell[files[i]] as IParsed);
892892
}
893893

894894
return byCell;
@@ -1292,6 +1292,8 @@ export class IDLIndex {
12921292
},
12931293
});
12941294
}
1295+
1296+
return false;
12951297
}
12961298

12971299
/**
@@ -1328,7 +1330,7 @@ export class IDLIndex {
13281330

13291331
try {
13301332
/** Get file from cache */
1331-
const parsed = this.parsedCache.get(files[i]);
1333+
const parsed = this.parsedCache.get(files[i]) as IParsed;
13321334

13331335
/** Post-process and check for global changes */
13341336
const didChange = await this.postProcessProFile(
@@ -1842,10 +1844,7 @@ export class IDLIndex {
18421844
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.ALL_FILES, {
18431845
files,
18441846
});
1845-
this.indexerPool.postToAll(
1846-
LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP,
1847-
undefined,
1848-
);
1847+
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP, {});
18491848

18501849
// track that we have PRO files
18511850
if (files.length > 0) {
@@ -1946,10 +1945,7 @@ export class IDLIndex {
19461945
await Promise.all(parsing);
19471946

19481947
// send message to clean up
1949-
this.indexerPool.postToAll(
1950-
LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP,
1951-
undefined,
1952-
);
1948+
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP, {});
19531949

19541950
/**
19551951
* Messages for global token synchronization
@@ -2008,10 +2004,7 @@ export class IDLIndex {
20082004
await Promise.all(synchronize);
20092005

20102006
// send message to clean up
2011-
this.indexerPool.postToAll(
2012-
LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP,
2013-
undefined,
2014-
);
2007+
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP, {});
20152008

20162009
// save stats
20172010
this.lastWorkspaceIndexStats.timePro = Math.floor(performance.now() - t0);
@@ -2084,10 +2077,7 @@ export class IDLIndex {
20842077
await Promise.all(parsing);
20852078

20862079
// send message to clean up
2087-
this.indexerPool.postToAll(
2088-
LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP,
2089-
undefined,
2090-
);
2080+
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP, {});
20912081

20922082
/**
20932083
* Messages for global token synchronization
@@ -2198,10 +2188,7 @@ export class IDLIndex {
21982188
await Promise.all(postProcessing);
21992189

22002190
// send message to clean up
2201-
this.indexerPool.postToAll(
2202-
LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP,
2203-
undefined,
2204-
);
2191+
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP, {});
22052192

22062193
/**
22072194
* Process our results
@@ -2233,10 +2220,7 @@ export class IDLIndex {
22332220
this.lastWorkspaceIndexStats.linesPro = lines;
22342221

22352222
// send message to clean up
2236-
this.indexerPool.postToAll(
2237-
LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP,
2238-
undefined,
2239-
);
2223+
this.indexerPool.postToAll(LSP_WORKER_THREAD_MESSAGE_LOOKUP.CLEAN_UP, {});
22402224
}
22412225

22422226
/**

0 commit comments

Comments
 (0)