-
Notifications
You must be signed in to change notification settings - Fork 36
Implement custom LS API for CodeMap generation in BI Copilot #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
yasithrashan
wants to merge
33
commits into
ballerina-platform:main
Choose a base branch
from
yasithrashan:feature/custom-ls-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
65fdb0b
Add CodeMap artifact generation core
yasithrashan e85f9bb
Add code map generation and LS extension support
yasithrashan 9073498
Add CodeMap test resources and configs
yasithrashan 9c93f35
Add class field support, improve types
yasithrashan cf099aa
Add listener type extraction to service
yasithrashan dae5b84
Improve type and record handling in CodeMapNodeTransformer
yasithrashan db1df80
Add listener init args and improve record types
yasithrashan 326181f
Add relative path and submodule support
yasithrashan 1712428
Add documentation extraction to CodeMap artifacts
yasithrashan 2893709
Add method to generate code map for specific files
yasithrashan 5dfcf74
Add comment extraction to CodeMapNodeTransformer
yasithrashan dfef6e2
Fix Checkstyle violations
yasithrashan b247bf3
Add incremental code map generation support
yasithrashan c4b3b06
Use system line separator for joining comments
yasithrashan 128cc9c
Refactor test resources and update config references
yasithrashan 55e096f
Move modifiers into properties in CodeMapArtifact
yasithrashan cd114fe
Refactor artifact type handling and add category property
yasithrashan c4c2325
Add import and constant support to CodeMap generator
yasithrashan 7f991e5
Merge codeMap APIs and support changed files
yasithrashan b333124
Refactor code map API and improve artifact structure
yasithrashan 8737b4a
Refactor CodeMap generator and tests
yasithrashan 45a92d1
Refactor property keys and comment extraction methods
yasithrashan af0c1f4
Remove unused lineRange method from Builder
yasithrashan 6be916b
Update copyright year and @since tags, fix test paths
yasithrashan 7f93769
Track changed files by relative path instead of name
yasithrashan 52561b0
Track didOpen events for CodeMap files
yasithrashan f2a56c9
Fix main function name in CodeMap
yasithrashan e760d4c
Update CodeMap to remove redundant fields
yasithrashan 37f8aa1
Rename lineRange to range and drop filePath
yasithrashan 11b6657
Rename AUTOMATION category to MAIN
yasithrashan 03da945
Remove category field from code map artifacts
yasithrashan 73a9ac4
Always create CodeMapFile and reorder imports
yasithrashan 56619ae
Add enum type handling to CodeMap transformer
yasithrashan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
...generator-core/src/main/java/io/ballerina/artifactsgenerator/codemap/CodeMapArtifact.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://www.wso2.com) | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.ballerina.artifactsgenerator.codemap; | ||
|
|
||
| import io.ballerina.compiler.syntax.tree.Node; | ||
| import io.ballerina.tools.text.LinePosition; | ||
| import io.ballerina.tools.text.LineRange; | ||
| import org.eclipse.lsp4j.Position; | ||
| import org.eclipse.lsp4j.Range; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Represents a code artifact extracted from Ballerina source code for the code map. | ||
| * | ||
| * @param name the name of the artifact | ||
| * @param type the type of the artifact (e.g., function, service, class) | ||
| * @param range the range in source code where this artifact is located | ||
| * @param properties additional properties of the artifact | ||
| * @param children nested artifacts contained within this artifact | ||
| * @since 1.6.0 | ||
| */ | ||
| public record CodeMapArtifact(String name, String type, Range range, | ||
| Map<String, Object> properties, List<CodeMapArtifact> children) { | ||
|
|
||
| // Property key constants | ||
| private static final String MODIFIERS = "modifiers"; | ||
| private static final String DOCUMENTATION = "documentation"; | ||
| private static final String COMMENT = "comment"; | ||
|
|
||
|
|
||
| /** | ||
| * Converts a Ballerina LineRange to an LSP4J Range. | ||
| * | ||
| * @param lineRange the Ballerina line range | ||
| * @return the corresponding LSP4J Range | ||
| */ | ||
| public static Range toRange(LineRange lineRange) { | ||
| return new Range(toPosition(lineRange.startLine()), toPosition(lineRange.endLine())); | ||
| } | ||
|
|
||
| /** | ||
| * Converts a Ballerina LinePosition to an LSP4J Position. | ||
| * | ||
| * @param linePosition the Ballerina line position | ||
| * @return the corresponding LSP4J Position | ||
| */ | ||
| public static Position toPosition(LinePosition linePosition) { | ||
| return new Position(linePosition.line(), linePosition.offset()); | ||
| } | ||
|
|
||
| public CodeMapArtifact { | ||
| properties = Collections.unmodifiableMap(properties); | ||
| children = Collections.unmodifiableList(children); | ||
| } | ||
|
|
||
| /** | ||
| * Builder class for constructing {@link CodeMapArtifact} instances. | ||
| */ | ||
| public static class Builder { | ||
| private String name; | ||
| private String type; | ||
| private Range range; | ||
| private final Map<String, Object> properties = new HashMap<>(); | ||
| private final List<CodeMapArtifact> children = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * Creates a new Builder initialized with the line range from the given syntax node. | ||
| * | ||
| * @param node the syntax node to extract line range from | ||
| */ | ||
| public Builder(Node node) { | ||
| this.range = toRange(node.lineRange()); | ||
| } | ||
|
|
||
| public Builder name(String name) { | ||
| this.name = name; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder type(String type) { | ||
| this.type = type; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder modifiers(List<String> modifiers) { | ||
| if (!modifiers.isEmpty()) { | ||
| this.properties.put(MODIFIERS, new ArrayList<>(modifiers)); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public Builder addProperty(String key, Object value) { | ||
| this.properties.put(key, value); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder addChild(CodeMapArtifact child) { | ||
| this.children.add(child); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder documentation(String documentation) { | ||
| return addProperty(DOCUMENTATION, documentation); | ||
| } | ||
|
|
||
| public Builder comment(String comment) { | ||
| return addProperty(COMMENT, comment); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Builds and returns the {@link CodeMapArtifact} instance. | ||
| * | ||
| * @return the constructed CodeMapArtifact | ||
| */ | ||
| public CodeMapArtifact build() { | ||
| return new CodeMapArtifact(name, type, range, | ||
| new HashMap<>(properties), new ArrayList<>(children)); | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...del-generator-core/src/main/java/io/ballerina/artifactsgenerator/codemap/CodeMapFile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://www.wso2.com) | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.ballerina.artifactsgenerator.codemap; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Represents a Ballerina source file with its extracted code map artifacts. | ||
| * | ||
| * @param artifacts the list of code map artifacts extracted from this file | ||
| * @since 1.6.0 | ||
| */ | ||
| public record CodeMapFile(List<CodeMapArtifact> artifacts) { | ||
|
|
||
| public CodeMapFile { | ||
| artifacts = artifacts == null ? Collections.emptyList() : Collections.unmodifiableList(artifacts); | ||
| } | ||
| } |
91 changes: 91 additions & 0 deletions
91
...rator-core/src/main/java/io/ballerina/artifactsgenerator/codemap/CodeMapFilesTracker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://www.wso2.com) | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.ballerina.artifactsgenerator.codemap; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * Tracks modified (changed or added) files per project for incremental code map generation. | ||
| * This singleton maintains a thread-safe record of file modifications between API calls. | ||
| * | ||
| * @since 1.6.0 | ||
| */ | ||
| public class CodeMapFilesTracker { | ||
|
|
||
| // Map: projectKey (URI) -> Set of modified (changed or added) file relative paths | ||
| private final Map<String, Set<String>> modifiedFilesMap; | ||
|
|
||
| private CodeMapFilesTracker() { | ||
| this.modifiedFilesMap = new ConcurrentHashMap<>(); | ||
| } | ||
|
|
||
| private static class Holder { | ||
| private static final CodeMapFilesTracker INSTANCE = new CodeMapFilesTracker(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the singleton instance of ChangedFilesTracker. | ||
| * | ||
| * @return the ChangedFilesTracker instance | ||
| */ | ||
| public static CodeMapFilesTracker getInstance() { | ||
| return Holder.INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * Track a changed file for a given project. | ||
| * | ||
| * @param projectKey the project identifier | ||
| * @param relativePath the relative path of the changed file from project root | ||
| */ | ||
| public void trackFile(String projectKey, String relativePath) { | ||
| modifiedFilesMap | ||
| .computeIfAbsent(projectKey, k -> ConcurrentHashMap.newKeySet()) | ||
| .add(relativePath); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves all tracked modified files for the given project. | ||
| * | ||
| * @param projectKey the project URI key | ||
| * @return list of modified file relative paths, or empty list if none tracked | ||
| */ | ||
| public List<String> getModifiedFiles(String projectKey) { | ||
| Set<String> files = modifiedFilesMap.get(projectKey); | ||
| if (files == null || files.isEmpty()) { | ||
| return Collections.emptyList(); | ||
| } | ||
| return new ArrayList<>(files); | ||
| } | ||
|
|
||
| /** | ||
| * Clears all tracked modified files for the given project. | ||
| * | ||
| * @param projectKey the project URI key | ||
| */ | ||
| public void clearModifiedFiles(String projectKey) { | ||
| modifiedFilesMap.remove(projectKey); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add a log for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack