Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { StateMachine } from '../../../../stateMachine';
import * as path from 'path';
import { Uri } from 'vscode';

export const DIAGNOSTICS_TOOL_NAME = "getCompilationErrors";

/**
* Diagnostic entry enriched with resolving hints
*/
Expand Down Expand Up @@ -128,6 +130,24 @@ export async function checkCompilationErrors(
};
}

// HACK: When the generated code includes `import ballerinax/client.config;` (without the quoted
// identifier), the language server returns diagnostics with the module name stripped to
// `ballerinax/.config as config` — omitting "client". As a workaround, we detect this and
// instruct the agent to use the correct quoted form `import ballerinax/'client.config;`
// instead of attempting to resolve the dependency automatically.
const hasInvalidClientModuleImport = enrichedDiagnostics.some(
d => d.code === "BCE2003" && d.message.includes("ballerinax/.config as config")
);
if (hasInvalidClientModuleImport) {
console.log(`[DiagnosticsUtils] Detected invalid client module import 'ballerinax/client.config'.`);
return {
diagnostics: enrichedDiagnostics,
message: `Found a module resolution error: the import 'import ballerinax/client.config;' is invalid. ` +
`Fix this by replacing the import statement with 'import ballerinax/'client.config;'. ` +
`After applying the fix, call the ${DIAGNOSTICS_TOOL_NAME} tool again to verify there are no remaining errors.`
};
}

console.log(`[DiagnosticsUtils] Enriched Diagnostics:`, enrichedDiagnostics);
return {
diagnostics: enrichedDiagnostics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ export async function isModuleNotFoundDiagsExist(diagnosticsResult: Diagnostics[

// Process each unique diagnostic only once
let projectModified = false;
for (const [_, { uri }] of uniqueDiagnosticMap.entries()) {
for (const [message, { uri }] of uniqueDiagnosticMap.entries()) {
// Skip resolving dependencies for the invalid config import pattern
if (message.includes("ballerinax/.config as config")) {
continue;
}

const dependenciesResponse = await langClient.resolveModuleDependencies({
documentIdentifier: {
uri: uri
Expand Down
Loading