Skip to content
Draft
Show file tree
Hide file tree
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 Jan 18, 2026
e85f9bb
Add code map generation and LS extension support
yasithrashan Jan 19, 2026
9073498
Add CodeMap test resources and configs
yasithrashan Jan 19, 2026
9c93f35
Add class field support, improve types
yasithrashan Jan 19, 2026
cf099aa
Add listener type extraction to service
yasithrashan Jan 19, 2026
dae5b84
Improve type and record handling in CodeMapNodeTransformer
yasithrashan Jan 19, 2026
db1df80
Add listener init args and improve record types
yasithrashan Jan 20, 2026
326181f
Add relative path and submodule support
yasithrashan Jan 20, 2026
1712428
Add documentation extraction to CodeMap artifacts
yasithrashan Jan 20, 2026
2893709
Add method to generate code map for specific files
yasithrashan Jan 20, 2026
5dfcf74
Add comment extraction to CodeMapNodeTransformer
yasithrashan Jan 20, 2026
dfef6e2
Fix Checkstyle violations
yasithrashan Jan 20, 2026
b247bf3
Add incremental code map generation support
yasithrashan Jan 22, 2026
c4b3b06
Use system line separator for joining comments
yasithrashan Jan 22, 2026
128cc9c
Refactor test resources and update config references
yasithrashan Jan 22, 2026
55e096f
Move modifiers into properties in CodeMapArtifact
yasithrashan Jan 22, 2026
cd114fe
Refactor artifact type handling and add category property
yasithrashan Jan 22, 2026
c4c2325
Add import and constant support to CodeMap generator
yasithrashan Jan 23, 2026
7f991e5
Merge codeMap APIs and support changed files
yasithrashan Jan 26, 2026
b333124
Refactor code map API and improve artifact structure
yasithrashan Jan 26, 2026
8737b4a
Refactor CodeMap generator and tests
yasithrashan Jan 26, 2026
45a92d1
Refactor property keys and comment extraction methods
yasithrashan Jan 27, 2026
af0c1f4
Remove unused lineRange method from Builder
yasithrashan Jan 27, 2026
6be916b
Update copyright year and @since tags, fix test paths
yasithrashan Jan 27, 2026
7f93769
Track changed files by relative path instead of name
yasithrashan Jan 27, 2026
52561b0
Track didOpen events for CodeMap files
yasithrashan Jan 27, 2026
f2a56c9
Fix main function name in CodeMap
yasithrashan Feb 5, 2026
e760d4c
Update CodeMap to remove redundant fields
yasithrashan Feb 9, 2026
37f8aa1
Rename lineRange to range and drop filePath
yasithrashan Feb 9, 2026
11b6657
Rename AUTOMATION category to MAIN
yasithrashan Feb 9, 2026
03da945
Remove category field from code map artifacts
yasithrashan Feb 12, 2026
73a9ac4
Always create CodeMapFile and reorder imports
yasithrashan Feb 12, 2026
56619ae
Add enum type handling to CodeMap transformer
yasithrashan Feb 12, 2026
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 @@ -37,8 +37,10 @@ dependencies {
implementation "org.ballerinalang:ballerina-tools-api:${ballerinaLangVersion}"
implementation "org.ballerinalang:ballerina-runtime:${ballerinaLangVersion}"
implementation "com.google.code.gson:gson:${gsonVersion}"
compileOnly "org.eclipse.lsp4j:org.eclipse.lsp4j:${eclipseLsp4jVersion}"

testImplementation "org.testng:testng:${testngVersion}"
testImplementation "org.eclipse.lsp4j:org.eclipse.lsp4j:${eclipseLsp4jVersion}"

balTools("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") {
transitive = false
Expand Down
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));
}
}
}
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);
}
}
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();

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

}
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);
}

}
Loading