Add LS API support for function, type discovery for workspaces#695
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis pull request introduces workspace-aware function and type search, public visibility modifiers for components, and library project support. It refactors search commands to handle workspace-level components alongside current integration, updates code generators to emit public qualifiers, and expands test configurations and resources to validate the new functionality. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FunctionSearchCommand
participant WorkspaceProject
participant CurrentProject
participant LibraryBuilder
Client->>FunctionSearchCommand: search(query)
activate FunctionSearchCommand
FunctionSearchCommand->>FunctionSearchCommand: buildWorkspaceNodes()
FunctionSearchCommand->>WorkspaceProject: buildProjectNodes(workspace_proj, Category.Builder, Category.Builder)
activate WorkspaceProject
WorkspaceProject->>WorkspaceProject: getFunctions(Project)
WorkspaceProject->>LibraryBuilder: createAvailableNode(FunctionSymbol, visibility, ...)
LibraryBuilder-->>WorkspaceProject: AvailableNode
WorkspaceProject-->>FunctionSearchCommand: nodes for CURRENT_WORKSPACE
deactivate WorkspaceProject
FunctionSearchCommand->>CurrentProject: buildProjectNodes(current_proj, Category.Builder, Category.Builder)
activate CurrentProject
CurrentProject->>CurrentProject: getFunctions(Project)
CurrentProject->>LibraryBuilder: createAvailableNode(FunctionSymbol, true, ...)
LibraryBuilder-->>CurrentProject: AvailableNode
CurrentProject-->>FunctionSearchCommand: nodes for CURRENT_INTEGRATION
deactivate CurrentProject
FunctionSearchCommand->>FunctionSearchCommand: buildLibraryNodes()
FunctionSearchCommand-->>Client: SearchResponse with CURRENT_WORKSPACE, CURRENT_INTEGRATION, imported functions
deactivate FunctionSearchCommand
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 18
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (6)
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_table_type_def.json (1)
92-92:⚠️ Potential issue | 🟡 MinorInconsistent type for
isArrayFLAG values.The
isPublicproperties were correctly updated to use booleanfalse, but theisArrayproperties at lines 92, 148, and 288 still use string"false". For consistency across FLAG-type fields, these should also be booleans.🔧 Proposed fix
At line 92:
- "value": "false", + "value": false,At line 148:
- "value": "false", + "value": false,At line 288:
- "value": "false", + "value": false,Also applies to: 148-148, 288-288
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_service_class_with_graphql_id_2.json (1)
100-116:⚠️ Potential issue | 🟡 MinorInconsistent value types across FLAG properties need alignment.
The
isPublicproperties use booleanfalse(lines 100–116, 251–267), but other FLAG-type properties in this file still use string"false":
- isArray (line 77)
- isDistinct (line 128)
- isIsolated (lines 145, 279)
- isReadOnly (line 162)
- isPrivate (line 245)
Update all FLAG properties to use boolean values for consistency, or document why
isPublicis handled differently.flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_with_custom_and_xml_annot.json (1)
47-63:⚠️ Potential issue | 🟡 MinorInconsistent value types for FLAG fields.
The
isPublicfield now correctly uses a boolean value (false), butisArray(line 92) still uses a string value ("false"). Both fields havefieldType: "FLAG"and should use consistent value types.Consider updating
isArray.valueto use a boolean as well for consistency.Also applies to: 81-97
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type2.json (1)
47-63:⚠️ Potential issue | 🟡 MinorInconsistent value types for FLAG fields.
The
isPublic.valueis now a boolean (false), butisArray.value(line 92) remains a string ("false"). For consistency, all FLAG type fields should use the same value type.Also applies to: 81-97
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_of_readonly_and_record_type_with_all_readonly_fields2.json (1)
47-63:⚠️ Potential issue | 🟡 MinorInconsistent value types for FLAG fields.
The
isPublic.valueis now a boolean (false), but other FLAG fields in this file still use string values:
isReadOnly.value:"true"(line 92)isArray.value:"false"(line 109)For consistency, all FLAG type fields should use the same value type (boolean).
Also applies to: 81-97, 98-114
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type4.json (1)
47-63:⚠️ Potential issue | 🟡 MinorInconsistent value types for FLAG fields across all record types.
The
isPublic.valuefields are correctly updated to booleanfalsefor all three record types (User, UserAddress, City), but the correspondingisArray.valuefields remain as string"false":
- User: lines 58 vs 92
- UserAddress: lines 415 vs 449
- City: lines 645 vs 679
For consistency, consider updating all FLAG type fields to use boolean values.
Also applies to: 81-97, 404-420, 438-454, 634-650, 668-684
🤖 Fix all issues with AI agents
In
`@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java`:
- Around line 331-346: The code casts symbol to Documentable unsafely; replace
the unchecked cast with an instanceof pattern match (as used in
buildProjectNodes) to safely bind a Documentable variable when symbol implements
Documentable, e.g., check "if (symbol instanceof Documentable documentable) {
... }" and then obtain documentation via documentable.documentation() to set
description, before computing score and adding to scoredTypes; ensure you still
guard on TypeDefinitionSymbol/ClassSymbol and skip unnamed symbols.
- Around line 175-182: The file imports EnumSymbol but getTypes() only filters
for TypeDefinitionSymbol and ClassSymbol; either remove the unused EnumSymbol
import or include enum discovery by adding `symbol instanceof EnumSymbol` to the
filter in the getTypes() method (the block using
PackageUtil.getCompilation(...).getSemanticModel(...).moduleSymbols().stream()).
Update the import/remove accordingly so the import list matches the actual
filter usage.
In
`@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/utils/SourceCodeGenerator.java`:
- Around line 139-148: generateEnumCodeSnippet currently omits the public
qualifier while generateTypeDefCodeSnippet uses isPublicFlagOn; update
generateEnumCodeSnippet to compute a publicQualifier (e.g., String
publicQualifier = isPublicFlagOn(enumData.properties()) ? "public " : "") and
inject it into the enum string template before the enum name so the emitted code
includes the `public` visibility when applicable; reference the
generateEnumCodeSnippet method, isPublicFlagOn, and
enumData.name()/enumData.properties() when making the change.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/config.json`:
- Around line 10-21: Update the TYPE search config's metadata to use "Types"
terminology: in the object with "label": "Current Integration" update
metadata.description (currently "Functions defined within the current
integration") to reference "Types" and change any metadata.keywords entries
("Function", "Functions") to "Type" or "Types" as appropriate so the description
and keywords consistently reflect this is a TYPE search config.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/default.json`:
- Around line 10-19: The metadata for the TYPE search config incorrectly uses
"Function"/"Functions"; update the "metadata" block for the "Current
Integration" category so the "description" refers to "Types defined within the
current integration" and update the "keywords" array to use "Type" (and any
other plural/singular occurrences of Function/Functions) to reflect this is a
TYPE search; edit the fields named "label", "description", and "keywords" in the
metadata object to make the terminology consistent.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/health.json`:
- Around line 9-20: Update the metadata for the "Current Integration" entry used
in the TYPE search (where "kind": "TYPE") to use "Types" terminology: change the
"description" value from "Functions defined within the current integration" to
something like "Types defined within the current integration" and replace any
"Function"/"Functions" occurrences in the "keywords" array (e.g., "Function")
with "Type"/"Types" so the "metadata" (label, description, keywords)
consistently reflects a TYPE search.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/imported_local_module.json`:
- Around line 10-21: Update the user-facing TYPE config metadata so it
consistently refers to "Types" instead of "Functions": change
metadata.description from "Functions defined within the current integration" to
something like "Types defined within the current integration" and update
metadata.keywords (e.g., replace "Function" with "Type" and any plural forms) so
the label/description/keywords in the JSON (metadata.label,
metadata.description, metadata.keywords) match the TYPE search context.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/imported_time.json`:
- Around line 10-21: Update the metadata in the TYPE search config so it refers
to "Types" not "Functions": change metadata.description from "Functions defined
within the current integration" to "Types defined within the current
integration" and replace "Function" in metadata.keywords with "Type" (the JSON
block containing metadata.label/metadata.description/metadata.keywords is in the
same object whose "kind" is "TYPE"). Ensure the label can remain "Current
Integration" or adjust if needed for consistency.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/submodule_description_match.json`:
- Around line 10-21: The metadata for this TYPE search is incorrectly
referencing functions: update the JSON under metadata for this entry so
metadata.description reads something like "Types defined within the current
integration" and replace/adjust metadata.keywords to use "Type" (and similar
type-related terms) instead of "Function"; ensure this entry's
metadata.description and metadata.keywords align with the search kind "TYPE".
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/submodule_exact_match.json`:
- Around line 10-21: The metadata.description for the TYPE search config
currently reads "Functions defined within the current integration" and should
refer to Types; update metadata.description to something like "Types defined
within the current integration" and adjust metadata.keywords (replace or add
"Type" instead of "Function") so the label "Current Integration" and the empty
items array remain correct and the UI doesn't confuse types with functions.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/submodule_no_match.json`:
- Around line 10-21: The metadata.description incorrectly refers to "Functions"
while the search kind is "TYPE"; update the metadata.description in this JSON
(look for the object with "label": "Current Integration" and "kind": "TYPE") to
read something like "Types defined within the current integration" so the
description matches the TYPE search category.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/submodule_prefix_match.json`:
- Around line 10-21: The metadata block for the "Current Integration" item uses
"Functions" wording but this file is a TYPE search (see "kind": "TYPE"); update
the metadata.description and metadata.keywords to refer to "Types" (e.g., change
"Functions defined within the current integration" to "Types defined within the
current integration" and replace "Function" keyword with "Type") so the label
"Current Integration", description, and keywords consistently reflect TYPE
searches.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/submodule_substring_match.json`:
- Around line 10-21: Update the metadata.description for this TYPE search
configuration so it references "Types" rather than "Functions": locate the JSON
object with "metadata" (keys "label": "Current Integration" and "description")
and change the description value to something like "Types defined within the
current integration" so it accurately reflects that this is a TYPE search.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/create_and_update/config/create_public_record_with_readonly_fields.json`:
- Around line 51-58: The JSON for properties.isArray currently sets "valueType":
"FLAG" but uses a string for "value" ("false"), which can break the loader;
change the "value" for the isArray entry from the string "false" to the boolean
false so the FLAG is represented as a boolean literal (update the
properties.isArray.value field accordingly while keeping
properties.isArray.valueType as "FLAG").
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/create_and_update/config/update_public_record_type.json`:
- Around line 150-165: The union member entries under the nested union for iA
currently have mismatched "name" values ("string" and "int") which should match
their "type" values; update the two objects where "type": "City" and "type":
"UserAddress" so their "name" fields are "City" and "UserAddress" respectively
(i.e., make the "name" property equal to the "type" property for those entries)
to ensure the union renders/validates as City|UserAddress.
- Around line 281-318: The docs for the field that currently read "Union of of
type-refs and a built-in type" must be corrected to "Union of type-refs and a
built-in type" in both the input docs entry and the expected output newText (the
generated comment inside the string for the User record type); locate the FIELD
with name "address" (or the docs string) and the "newText" value under
"test_pack2/types.bal" and remove the duplicated "of" so the user-facing
documentation and the expected patch output match the corrected phrase.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_graphql_type/config/get_service_class3.json`:
- Line 161: The flag fields in this JSON sample are inconsistent: `isPublic`
uses boolean values while other FLAG-type properties (`isPrivate`, `isIsolated`,
`isReadOnly`, `isArray`, `isDistinct`) remain as string values; update those
fields to use boolean true/false consistently (e.g., change `"value": "false"`
to `"value": false`) for `isPrivate`, `isIsolated`, `isReadOnly`, `isArray`, and
`isDistinct` so all FLAG-type properties match the `isPublic` boolean
normalization.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_with_escaped_field_name.json`:
- Line 58: The FLAG fields are using inconsistent types: change the
isArray.value property (currently the string "false") to a boolean false to
match isPublic.value and the fieldType "FLAG"; locate the isArray entry in the
same JSON (field name "isArray", "fieldType": "FLAG") and update its "value"
from the string "false" to the boolean false.
🧹 Nitpick comments (13)
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_with_json_annot_in_fields.json (1)
47-97: Inconsistent boolean normalization between FLAG-type properties.The
isPublic.valueon line 58 is correctly normalized to a booleanfalse, butisArray.valueon line 92 still uses the string"false". Both properties have"fieldType": "FLAG", so they should use consistent value types.If this normalization is intentional for FLAG properties, consider applying the same change to
isArray:♻️ Proposed fix for consistency
"isArray": { "metadata": { "label": "Is array type", "description": "Is this type an array or list value" }, "types": [ { "fieldType": "FLAG", "selected": true } ], - "value": "false", + "value": false, "optional": true, "editable": true, "advanced": true, "hidden": false },flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_object_type_of_readonly_and_object_type.json (1)
92-92: Consider updating other FLAG fields for consistency.The
isPublicfields are now correctly using boolean values, but other FLAG type fields in this file still use string representations:
- Line 92:
isReadOnlyuses"value": "true"- Line 109:
isIsolateduses"value": "false"- Line 167:
isPrivateuses"value": "false"- Line 201:
isIsolateduses"value": "false"For consistency and to avoid potential type coercion issues, consider updating these fields to use actual booleans as well.
♻️ Proposed fix for consistency
"isReadOnly": { ... - "value": "true", + "value": true, ... }, "isIsolated": { ... - "value": "false", + "value": false, ... }, ... "isPrivate": { ... - "value": "false", + "value": false, ... }, ... "isIsolated": { ... - "value": "false", + "value": false, ... }Also applies to: 109-109, 167-167, 201-201
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_with_readonly_fields.json (1)
58-92: Keep FLAG value types consistent.
Line 58 now uses a boolean, but Line 92 still has"false"as a string for another FLAG. If FLAG values are being normalized to booleans, consider aligningisArray.valueto avoid mixed typing in the same config.♻️ Suggested tweak
- "value": "false", + "value": false,flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_of_readonly_and_record_type_with_all_readonly_fields1.json (1)
58-58: Consider normalizing other FLAG values to booleans for consistency.
isPublicnow uses a boolean, whileisReadOnly/isArraystill use string literals. If FLAG consumers expect booleans, mixed typing can lead to inconsistent parsing. Consider normalizing the remaining FLAG values in this fixture.♻️ Suggested normalization
- "value": "true", + "value": true, ... - "value": "false", + "value": false,flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_array_type_def.json (1)
58-58: Consider aligning all FLAG-type properties to use boolean values.The
isPublicfield is correctly changed to use a booleanfalse, but other FLAG-type properties likeisArray(line 92) still use string values ("true"). For consistency, consider converting all FLAG fields to proper JSON booleans in this test fixture.If this is intentional or out of scope for this PR, feel free to skip.
Also applies to: 92-92
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_with_reference_type_with_same_package_with_suffix.json (1)
47-63: Normalize remaining boolean flags in this fixture.Now that
isPublic.valueis a JSON boolean, theisArray.valuefields in this same file are still string literals. To avoid mixed types in the test fixture (and potential schema drift), consider converting those to booleans too (Line 92, Line 246, Line 337).♻️ Suggested updates for remaining `isArray` flags
@@ - "value": "false", + "value": false, @@ - "value": "false", + "value": false, @@ - "value": "false", + "value": false,flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_union_type1.json (1)
58-58: Correct boolean conversion forisPublicfields.The conversion of
isPublic.valuefrom string literals to boolean literals is appropriate and aligns with the PR's goal of adding public visibility support.However, note there's an inconsistency: other FLAG-type properties in this file (e.g.,
isArrayat line 92,isReadOnlyat line 530) still use string values like"false"and"true". Consider normalizing all FLAG fields to boolean for consistency in a follow-up.,
Also applies to: 205-205, 327-327, 496-496, 766-766, 968-968
flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/FormBuilder.java (1)
1074-1091: Inconsistent handling of FLAG values across similar methods.The
isPublicmethod now passes the boolean value directly (line 1083), but other similar FLAG methods still useString.valueOf(value):
isPrivate(line 1102)isIsolated(line 1121)isReadOnly(line 1140)isDistinct(line 1159)For consistency, consider updating all FLAG-type methods to use the same value handling approach.
Example fix for consistency
public FormBuilder<T> isPrivate(boolean value, boolean optional, boolean editable, boolean advanced) { propertyBuilder .metadata() .label(Property.IS_PRIVATE_LABEL) .description(Property.IS_PRIVATE_DOC) .stepOut() .editable(editable) .optional(optional) .advanced(advanced) - .value(String.valueOf(value)) + .value(value) .type() .fieldType(Property.ValueType.FLAG) .selected(true) .stepOut() .editable(); addProperty(Property.IS_PRIVATE_KEY); return this; }Apply similar changes to
isIsolated,isReadOnly, andisDistinctmethods.flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/node/FunctionDefinitionBuilder.java (1)
79-86: Confirm library default visibility override.
This sets theisPublicdefault tofalsefor all templates. The PR objective says library components should be public by default—please verify the library flow overrides this, or consider parameterizing the default.flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_public_record_type.json (1)
1-335: Normalize FLAG values to booleans for consistency.
This fixture mixes boolean literals (e.g.,isPublic) with string"true"/"false"for other FLAG fields (isArray,isReadOnly). Please verify the consumer accepts both, or normalize to booleans to avoid parsing mismatches.flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/FunctionSearchCommand.java (1)
197-226: Avoid package-name collisions when skipping the current project.
The skip check compares onlypackageName. If a workspace can include different projects sharing the same package name, those could be skipped unintentionally—consider comparing project source root or a project id instead.flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java (1)
373-377: Formatting issue: inconsistent indentation onScoredTyperecord.The record definition has extra indentation that doesn't match the rest of the class.
♻️ Fix indentation
- /** - * Helper record to store type definition and class symbols along with their relevance scores for ranking. - */ - private record ScoredType(Symbol symbol, String typeName, String description, int score) { + /** + * Helper record to store type definition and class symbols along with their relevance scores for ranking. + */ + private record ScoredType(Symbol symbol, String typeName, String description, int score) { }flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/types_manager/get_type/config/get_record_type_of_readonly_and_record_type.json (1)
58-58: Inconsistent value types for FLAG fields.The
isPublic.valueis a booleanfalse, butisReadOnly.value(line 92) andisArray.value(line 109) are strings"true"and"false"respectively. All three properties havefieldType: "FLAG"and should use consistent value types.
...erator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java
Show resolved
Hide resolved
...erator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java
Show resolved
Hide resolved
...rator-core/src/main/java/io/ballerina/flowmodelgenerator/core/utils/SourceCodeGenerator.java
Show resolved
Hide resolved
...modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/config.json
Show resolved
Hide resolved
...odules/flow-model-generator-ls-extension/src/test/resources/search/config/types/default.json
Show resolved
Hide resolved
...ources/types_manager/create_and_update/config/create_public_record_with_readonly_fields.json
Show resolved
Hide resolved
...ion/src/test/resources/types_manager/create_and_update/config/update_public_record_type.json
Show resolved
Hide resolved
...ion/src/test/resources/types_manager/create_and_update/config/update_public_record_type.json
Show resolved
Hide resolved
...s-extension/src/test/resources/types_manager/get_graphql_type/config/get_service_class3.json
Show resolved
Hide resolved
...ion/src/test/resources/types_manager/get_type/config/get_record_with_escaped_field_name.json
Show resolved
Hide resolved
…eneration with public qualifier
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (2)
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/source/workspace1/package1/main.bal (1)
34-42: Minor:findMaxdoesn't handle empty arrays.Accessing
values[0]on an empty array will cause a runtime panic. While this is acceptable for a test fixture, consider adding a guard if this code might be referenced as an example.💡 Optional fix
public function findMax(int[] values) returns int { + if values.length() == 0 { + return 0; // or panic/return error + } int max = values[0]; foreach var val in values {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/source/workspace1/package1/main.bal` around lines 34 - 42, The function findMax reads values[0] without guarding against an empty array; add an early check in findMax to handle empty inputs (e.g., if values is empty, either throw a descriptive error or return a sensible default) before accessing values[0], using the array-length/isEmpty check appropriate for the codebase, and if you choose to return an error adjust the function signature to return an error union accordingly.flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java (1)
377-386: Unusedsymbolfield inScoredTyperecord and formatting issue.
Indentation: The Javadoc and record have inconsistent indentation (extra leading spaces).
Unused field: The
symbolfield is stored but never accessed after creation — bothbuildProjectNodes()andbuildImportedLocalModules()only usetypeName(),description(), andscore(). Consider removing it to reduce memory overhead.♻️ Proposed refactor
- /** - * Helper record to store type definition and class symbols along with their relevance scores for ranking. - * - * `@param` symbol the symbol representing the type - * `@param` typeName the name of the type - * `@param` description the description of the type - * `@param` score the relevance score for ranking - */ - private record ScoredType(Symbol symbol, String typeName, String description, int score) { + /** + * Helper record to store type metadata along with relevance scores for ranking. + * + * `@param` typeName the name of the type + * `@param` description the description of the type + * `@param` score the relevance score for ranking + */ + private record ScoredType(String typeName, String description, int score) { }Then update callers:
- scoredTypes.add(new ScoredType(typeSymbol, typeName, description, score)); + scoredTypes.add(new ScoredType(typeName, description, score));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java` around lines 377 - 386, Remove the unused Symbol field from the ScoredType record and fix the Javadoc/record indentation: change the record declaration to only hold (String typeName, String description, int score) and update all instantiations to pass only those three values; update callers in buildProjectNodes() and buildImportedLocalModules() that create ScoredType instances so they no longer supply or expect a Symbol, and adjust any usages to call typeName(), description(), and score() as before; also normalize the leading spaces on the Javadoc and record declaration so indentation matches surrounding code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/FunctionSearchCommand.java`:
- Around line 186-196: The getFunctions(Project project) method currently only
queries the default module via currentPackage.getDefaultModule().moduleId(), so
functions in other modules are omitted; update it to iterate all modules in the
Package (e.g., currentPackage.modules() or similar API) and for each module call
PackageUtil.getCompilation(currentPackage).getSemanticModel(module.moduleId()).moduleSymbols(),
filter for SymbolKind.FUNCTION excluding AutomationBuilder.MAIN_FUNCTION_NAME,
cast to FunctionSymbol and aggregate into a single list to return; ensure you
still use PackageUtil.getCompilation(currentPackage) and preserve the existing
filtering and casting logic.
In
`@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java`:
- Around line 363-369: The Codedata built in buildImportedLocalModules() is
missing the node kind set in buildProjectNodes(); update the Codedata builder in
TypeSearchCommand.buildImportedLocalModules() to call .node(NodeKind.TYPEDESC)
so imported module entries match buildProjectNodes() behavior; locate the
Codedata.Builder<>(null) call that sets org/module/packageName/symbol/version
and add .node(NodeKind.TYPEDESC) before .build() to ensure consistent NodeKind
for typedesc entries.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/workspace_pkg1_default.json`:
- Around line 664-726: The JSON contains duplicate imported-function entries for
the io package (fileReadJson, fileReadString, fileWriteJson, fileWriteString);
remove the repeated objects so each function symbol (codedata.symbol:
"fileReadJson", "fileReadString", "fileWriteJson", "fileWriteString") appears
only once in the array, leaving the original/first occurrence intact and
deleting the subsequent duplicate blocks.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/workspace_pkg1_default.json`:
- Around line 10-17: The metadata for the TYPE category is inconsistent:
although this fixture is for kind=TYPE, the "description" and "keywords" refer
to "Functions"; update the "description" value to something like "Types
available in the current workspace" and replace keyword entries ("Function",
"Functions", "Local" if needed) with appropriate type-focused terms (e.g.,
"Type", "Types", "Workspace") so the metadata aligns with kind=TYPE and the
label "Current Workspace".
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/workspace_pkg2_default.json`:
- Around line 10-17: The metadata for the fixture marked kind=TYPE is
inconsistent: update the "metadata" fields in workspace_pkg2_default.json so the
"description" and any "keywords" no longer reference "Functions" but instead say
"Types" (e.g., change "Functions available in the current workspace" to "Types
available in the current workspace" and replace keyword "Function" with "Type"),
leaving "label" intact; ensure the keywords array reflects type-focused terms
and the description aligns with kind=TYPE.
---
Nitpick comments:
In
`@flow-model-generator/modules/flow-model-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java`:
- Around line 377-386: Remove the unused Symbol field from the ScoredType record
and fix the Javadoc/record indentation: change the record declaration to only
hold (String typeName, String description, int score) and update all
instantiations to pass only those three values; update callers in
buildProjectNodes() and buildImportedLocalModules() that create ScoredType
instances so they no longer supply or expect a Symbol, and adjust any usages to
call typeName(), description(), and score() as before; also normalize the
leading spaces on the Javadoc and record declaration so indentation matches
surrounding code.
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/source/workspace1/package1/main.bal`:
- Around line 34-42: The function findMax reads values[0] without guarding
against an empty array; add an early check in findMax to handle empty inputs
(e.g., if values is empty, either throw a descriptive error or return a sensible
default) before accessing values[0], using the array-length/isEmpty check
appropriate for the codebase, and if you choose to return an error adjust the
function signature to return an error union accordingly.
...or-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/FunctionSearchCommand.java
Show resolved
Hide resolved
...erator-core/src/main/java/io/ballerina/flowmodelgenerator/core/search/TypeSearchCommand.java
Show resolved
Hide resolved
...enerator-ls-extension/src/test/resources/search/config/functions/workspace_pkg1_default.json
Show resolved
Hide resolved
...el-generator-ls-extension/src/test/resources/search/config/types/workspace_pkg1_default.json
Show resolved
Hide resolved
...el-generator-ls-extension/src/test/resources/search/config/types/workspace_pkg2_default.json
Show resolved
Hide resolved
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/custom_default.json (1)
513-576:⚠️ Potential issue | 🟡 MinorRemove duplicate imported-function entries.
The
iomodule items array contains duplicates:fileReadJson(lines 369-384 and 513-528),fileReadString(lines 321-336 and 529-544),fileWriteJson(lines 449-464 and 545-560), andfileWriteString(lines 401-416 and 561-576). This can cause ambiguous test results.🧹 Suggested fix (remove duplicates starting at line 513)
- { - "metadata": { - "label": "fileReadJson", - ... - }, - ... - }, - { - "metadata": { - "label": "fileReadString", - ... - }, - ... - }, - { - "metadata": { - "label": "fileWriteJson", - ... - }, - ... - }, - { - "metadata": { - "label": "fileWriteString", - ... - }, - ... - },Remove the four duplicate entries (fileReadJson, fileReadString, fileWriteJson, fileWriteString) that appear after
openWritableFile.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/custom_default.json` around lines 513 - 576, Remove the duplicated io module function entries for "fileReadJson", "fileReadString", "fileWriteJson", and "fileWriteString" that are repeated later in the array (the duplicate objects with metadata.label matching those four names that appear after the original "openWritableFile" entry); delete those four duplicate JSON objects and keep the first occurrences earlier in the file so the io items array contains only one entry per symbol (refer to the codedata.symbol fields "fileReadJson", "fileReadString", "fileWriteJson", "fileWriteString" to locate the duplicates).flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/custom_default2.json (1)
513-576:⚠️ Potential issue | 🟡 MinorRemove duplicate imported-function entries.
The
iomodule items array contains duplicates:fileReadJson,fileReadString,fileWriteJson, andfileWriteStringappear twice (first around lines 369-416 and again at lines 513-576).🧹 Suggested fix (remove duplicates)
- { - "metadata": { - "label": "fileReadJson", - "description": "Reads file content as a JSON...", - ... - }, - ... - }, - { - "metadata": { - "label": "fileReadString", - ... - }, - ... - }, - { - "metadata": { - "label": "fileWriteJson", - ... - }, - ... - }, - { - "metadata": { - "label": "fileWriteString", - ... - }, - ... - },Remove the four duplicate entries that appear after
openWritableFile.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/custom_default2.json` around lines 513 - 576, Duplicate function entries for the io module (fileReadJson, fileReadString, fileWriteJson, fileWriteString) were added twice; remove the second set of duplicates that appear after openWritableFile so each function symbol (fileReadJson, fileReadString, fileWriteJson, fileWriteString) exists only once in the items array, ensuring you delete the repeated objects (the ones with codedata.symbol matching those four names) and leave the original entries intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/custom_default.json`:
- Around line 513-576: Remove the duplicated io module function entries for
"fileReadJson", "fileReadString", "fileWriteJson", and "fileWriteString" that
are repeated later in the array (the duplicate objects with metadata.label
matching those four names that appear after the original "openWritableFile"
entry); delete those four duplicate JSON objects and keep the first occurrences
earlier in the file so the io items array contains only one entry per symbol
(refer to the codedata.symbol fields "fileReadJson", "fileReadString",
"fileWriteJson", "fileWriteString" to locate the duplicates).
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/custom_default2.json`:
- Around line 513-576: Duplicate function entries for the io module
(fileReadJson, fileReadString, fileWriteJson, fileWriteString) were added twice;
remove the second set of duplicates that appear after openWritableFile so each
function symbol (fileReadJson, fileReadString, fileWriteJson, fileWriteString)
exists only once in the items array, ensuring you delete the repeated objects
(the ones with codedata.symbol matching those four names) and leave the original
entries intact.
---
Duplicate comments:
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/functions/workspace_pkg1_default.json`:
- Around line 665-728: The JSON contains duplicate function entries for the io
module (symbols fileReadJson, fileReadString, fileWriteJson, fileWriteString);
remove the redundant block that repeats these objects so each unique function
(identified by codedata.symbol and codedata.module/org/version) appears only
once in the file (keep the preferred/earlier occurrence and delete the duplicate
group around the second instance).
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/search/config/types/workspace_pkg1_default.json`:
- Around line 10-19: The metadata.keywords array for the fixture contains
"Function" which likely conflicts with this fixture's intent as a kind: "TYPE"
search; open the JSON around the metadata object and either remove or replace
"Function" in metadata.keywords with a type-appropriate keyword (e.g., "Type" or
"Data Type") or, if cross-search is intentional, add a comment or a clarifying
keyword (e.g., "CrossSearch") and update any tests that rely on this keyword;
ensure you modify the metadata object where "label":"Current Workspace" and
"keywords" are defined so the keywords align with kind: "TYPE".
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
There was a problem hiding this comment.
Pull request overview
This pull request extends the Language Server API to support workspace-wide function and type discovery, enabling better cross-project visibility and reuse in multi-package workspaces. The changes introduce public visibility qualifiers, workspace-aware search capabilities, and update test fixtures to use proper boolean types.
Changes:
- Added workspace-level function and type search with visibility filtering (only public symbols from other projects are exposed)
- Introduced
isPublicflag support throughout the codebase for functions, types, and enums with proper boolean type handling - Refactored search commands to distinguish between current integration, workspace, and library components with new categorization
Reviewed changes
Copilot reviewed 147 out of 147 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| SourceCodeGenerator.java | Added public qualifier generation for enums and type definitions |
| FunctionSearchCommand.java | Refactored to support workspace-wide function discovery with visibility filtering |
| TypeSearchCommand.java | Extended to include workspace symbols (TypeDefinitionSymbol and ClassSymbol) with scoring/ranking |
| FormBuilder.java | Changed isPublic value type from String to boolean |
| Category.java | Updated CURRENT_INTEGRATION description and added CURRENT_WORKSPACE category |
| FunctionDefinitionBuilder.java | Added isPublic property initialization and source generation |
| ProjectInfoBuilder.java | Implemented library project detection via bi.validator import |
| ProjectInfoResponse.java | Added isLibrary field to project metadata |
| Test resources (170+ files) | Updated JSON fixtures to use boolean values instead of strings for flags, added workspace test sources and expected outputs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
✅ Created PR with unit tests: #707 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 147 out of 147 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...les/flow-model-generator-ls-extension/src/test/resources/agents_manager/config/get_tool.json
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/to_source/config/function_definition21.json (1)
75-75: Minor: Unusual spacing in generated function signature.The
newTextcontains"public function initialize( ) "with a space inside the parentheses and a trailing space. If this is the expected formatting convention for the code generator, this is fine. Otherwise, consider whether"public function initialize() "or"public function initialize()"is more appropriate.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/to_source/config/function_definition21.json` at line 75, The generated signature for function initialize currently uses "newText" with an extra space inside the parentheses and a trailing space ("public function initialize( ) "), so update the code-generation logic that builds the function signature (where "newText" is composed for function initialize) to produce no space inside the parentheses and no trailing space (e.g. "public function initialize()" or at minimum "public function initialize() "); trim or adjust the string concatenation/format helper that emits parentheses to remove the internal and trailing spaces and ensure this formatting is applied consistently for other function signatures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/to_source/config/data_mapper_definition15.json`:
- Line 158: The generated function signature string for mapPersonToEmployee
contains an extra space after the opening parenthesis in the "newText" value
("mapPersonToEmployee( Person person)"); update the generator or the test
fixture so the signature is emitted as "mapPersonToEmployee(Person person)" by
trimming or avoiding insertion of a space after '(' when constructing the
function parameter list (look for the code that builds the function
signature/newText for mapPersonToEmployee and remove the added space).
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/to_source/config/function_definition20.json`:
- Around line 2-13: The JSON fixture has a mismatched file name in
diagram.codedata.lineRange.fileName (it is "single.bal") which must match the
declared source/output "empty.bal"; update diagram.codedata.lineRange.fileName
to "empty.bal" (and any other occurrences referenced in the same fixture, e.g.,
the block around lines 109-121) so the test harness applies ranges to the
correct file and lookups succeed.
---
Nitpick comments:
In
`@flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/to_source/config/function_definition21.json`:
- Line 75: The generated signature for function initialize currently uses
"newText" with an extra space inside the parentheses and a trailing space
("public function initialize( ) "), so update the code-generation logic that
builds the function signature (where "newText" is composed for function
initialize) to produce no space inside the parentheses and no trailing space
(e.g. "public function initialize()" or at minimum "public function initialize()
"); trim or adjust the string concatenation/format helper that emits parentheses
to remove the internal and trailing spaces and ensure this formatting is applied
consistently for other function signatures.
...del-generator-ls-extension/src/test/resources/to_source/config/data_mapper_definition15.json
Outdated
Show resolved
Hide resolved
...-model-generator-ls-extension/src/test/resources/to_source/config/function_definition20.json
Show resolved
Hide resolved
b689fce
into
ballerina-platform:main
Purpose
$title
Fixes wso2/product-ballerina-integrator#2364
Fixes wso2/product-ballerina-integrator#2368
Fixes wso2/product-ballerina-integrator#2382
LS API Support for Function and Type Discovery for Workspaces
Overview
This pull request adds Language Server API support for workspace-wide discovery of functions and types, enabling users to discover and reuse components defined across multiple projects within a workspace while maintaining proper visibility controls through public/private access modifiers.
Core Capabilities
1. Workspace-Level Component Discovery
CURRENT_WORKSPACEcategory to organize components available across the entire workspace alongside the existingCURRENT_INTEGRATIONcategoryFunctionSearchCommandwith workspace-aware node building that gathers and categorizes functions from all workspace projectsTypeSearchCommandwith integrated workspace scanning and support for class symbols alongside type definitions2. Public Visibility Qualifier Support
FunctionDefinitionBuilderandDataMapperDefinitionBuilderto conditionally emitpublickeywords in generated codeSourceCodeGeneratorto support public visibility for enums and type definitions3. Workspace Project Metadata and Detection
ProjectInfoBuilderthat identifies projects configured as library modulesProjectInfoResponsewithisLibraryfield to expose project type information to API consumers4. Enhanced Code Generation for Public Components
ModuleNodeAnalyzerto recognize and process public qualifiers from source syntaxTesting and Validation
Implementation Details
ScoredTyperecord for consistent type ranking and metadata handling in type searchesOutcomes
This enhancement enables better component organization and reuse across multi-project Ballerina workspaces, allowing developers to leverage library and shared components more effectively while maintaining clear visibility boundaries through public visibility modifiers.