Skip to content

#1167: automatic project import vscode - #2263

Open
QuangAnhLe wants to merge 8 commits into
devonfw:mainfrom
QuangAnhLe:feature/1167-automatic-project-import-vscode
Open

#1167: automatic project import vscode#2263
QuangAnhLe wants to merge 8 commits into
devonfw:mainfrom
QuangAnhLe:feature/1167-automatic-project-import-vscode

Conversation

@QuangAnhLe

@QuangAnhLe QuangAnhLe commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This PR fixes #1167

Implemented changes:

Adds automatic VSCode workspace settings import for Maven and Gradle projects. When a repository is imported, the Vscode.importRepository() method:

  • Detects whether the project uses Maven (pom.xml) or Gradle (build.gradle).
  • Merges the VSCode settings template from vscode/workspace/repository/.vscode/settings.json (in the settings repository) into the workspace's .vscode/settings.json.
  • Resolves environment variables (e.g. ${PROJECT_PATH}) in the template with the relative project path.
  • Creates the .vscode folder if it does not already exist.

Testing instructions

  1. Run the unit tests:
    mvn -Dtest="VscodeTest#testVscodeMvnRepositoryImport,VscodeTest#testVscodeGradleRepositoryImport" test -pl cli
  2. Both tests should pass, verifying Maven and Gradle project import.
  3. Run all VSCode tests to ensure no regression:
    mvn -Dtest="VscodeTest" test -pl cli
  4. Manual test (requires a settings repository with vscode/workspace/repository/.vscode/settings.json):
    • Clone a Maven or Gradle project into <IDE_HOME>/workspaces//.
    • Run ide import (or whichever command triggers importRepository).
    • Verify that /.vscode/settings.json has been created and contains the merged settings with resolved variables (e.g.
      ${PROJECT_PATH} replaced with the

Checklist for this PR

Make sure everything is checked before merging this PR. For further info please also see
our DoD.

  • When running mvn clean test locally all tests pass and build is successful
  • PR title is of the form #«issue-id»: «brief summary» (e.g. #921: fixed setup.bat). If no issue ID exists, title only.
  • PR top-level comment summarizes what has been done and contains link to addressed issue(s)
  • PR and issue(s) have suitable labels
  • Issue is set to In Progress and assigned to you or there is no issue (might happen for very small PRs)
  • You followed all coding conventions
  • You have added the issue implemented by your PR in CHANGELOG.adoc unless issue is labeled
    with internal
  • You have formulated clear instructions on how to test your contribution under "Testing instructions"

@coveralls

coveralls commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 31963676067

Warning

No base build found for commit 31dabbf on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 72.916%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 17582
Covered Lines: 13371
Line Coverage: 76.05%
Relevant Branches: 7765
Covered Branches: 5111
Branch Coverage: 65.82%
Branches in Coverage %: Yes
Coverage Strength: 3.23 hits per line

💛 - Coveralls

@QuangAnhLe QuangAnhLe added vscode Microsoft visual studio code enhancement New feature or request repository Commandlet to clone, build or import git repositories labels Aug 4, 2026
@QuangAnhLe QuangAnhLe moved this from 🆕 New to Team Review in IDEasy board Aug 4, 2026
@QuangAnhLe QuangAnhLe self-assigned this Aug 4, 2026
@JoelAdbu JoelAdbu self-assigned this Aug 5, 2026

@JoelAdbu JoelAdbu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested manually, looks good to me.

@JoelAdbu JoelAdbu moved this from Team Review to 👀 In review in IDEasy board Aug 6, 2026
@hohwille hohwille changed the title Feature/1167 automatic project import vscode #1167: automatic project import vscode Aug 11, 2026

@hohwille hohwille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@QuangAnhLe thanks for your PR. You got the general idea right but this cannot work as is yet. I left some review comments to address before we can merge. Thanks 👍

Comment on lines +123 to +137
@Override
public void importRepository(Path repositoryPath) {
CommandletManager commandletManager = this.context.getCommandletManager();
for (Entry<Class<? extends LocalToolCommandlet>, String> entry : BUILD_TOOL_TO_TEMPLATE.entrySet()) {
LocalToolCommandlet buildTool = commandletManager.getCommandlet(entry.getKey());
Path buildDescriptor = buildTool.findBuildDescriptor(repositoryPath);
if (buildDescriptor != null) {
String templateFilename = entry.getValue();
LOG.debug("Found build descriptor {} so merging template {}", buildDescriptor, templateFilename);
mergeSettings(repositoryPath, templateFilename);
return;
}
}
LOG.warn("No supported build descriptor was found for project import in {}", repositoryPath);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct, but we are coming back to copy&paste culture.
My suggestion would be to move this entire method to IdeToolCommandlet.
Then instead of accessing the map from constant (BUILD_TOOL_TO_TEMPLATE), simply use getBuildTool2TemplateMap() add a method in the same class:

protected Map<Class<? extends LocalToolCommandlet>, String> getBuildTool2TemplateMap() {
  return Map.of();
}

Then Intellij and Vscode can override this method and return their constant.

BTW: Why was importRepository API Signature declared in ToolCommandlet - this only makes sense for IdeToolCommandlet so I would even move the declaration there and fix the usage in RepositoryCommandlet accordingly as everything else does not make any sense to me.

Comment on lines +153 to +185
/**
* Merges the VSCode settings template into the workspace's {@code .vscode/settings.json}.
*
* @param repositoryPath the {@link Path} to the repository to import.
* @param configFilePath the filename of the config file (e.g. {@code settings.json}).
*/
private void mergeSettings(Path repositoryPath, String configFilePath) {
Path templatePath = this.context.getSettingsPath().resolve(TEMPLATE_LOCATION);
Path templateFile = templatePath.resolve(configFilePath);
if (!Files.exists(templateFile)) {
throw new CliException(
"Cannot import project into workspace: template file not found at " + templateFile + "\n"
+ "Please do an upstream merge of your settings git repository.");
}
Path workspacesPath = this.context.getIdeHome().resolve(IdeContext.FOLDER_WORKSPACES);
Path workspacePath = this.context.getFileAccess().findAncestor(repositoryPath, workspacesPath, 1);
if (workspacePath == null) {
throw new CliException(
"Cannot import project into workspace: could not find workspace from " + repositoryPath);
}
JsonMerger jsonMerger = new JsonMerger(this.context);
EnvironmentVariables environmentVariables = getVscodeEnvironmentVariables(workspacePath.relativize(repositoryPath));
Path vscodeFolder = workspacePath.resolve(FOLDER_VSCODE);
Path workspaceFile = vscodeFolder.resolve(configFilePath);

// Ensure .vscode folder exists
this.context.getFileAccess().mkdirs(vscodeFolder);

// Merge template into workspace settings (template acts as "setup" for creation, also as "update" for variable resolution)
jsonMerger.merge(templateFile, templateFile, environmentVariables, workspaceFile);

LOG.debug("Merged VSCode settings into {} for repository at {}", workspaceFile, repositoryPath);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The same here. Seems like a complete copy of Intellij.mergeConfig.
Move and centralise in IdeToolCommandlet. Instead of using TEMPLATE_LOCATION constant, build it dynamically.
p.s.: I already gave that feedback for the initial Intellij project import to avoid such redundancies since I saw all this coming - but it seems my review comments where not properly addressed (see PR #1466).

@@ -0,0 +1,3 @@
{
"java.project.rootPath": "$[PROJECT_PATH]"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not the way how to "import" a project.
Please note that you can import multiple projects into the same workspace and here you only have a single property that the 2nd import would override from the 1st one.
Further, if that template is complete and correct, you first need to create a PR for ide-settings that has to be merged before this PR can be merged as otherwise we will always end up in the CliException that you are throwing if the template file is not present.

Comment thread CHANGELOG.adoc
* https://github.com/devonfw/IDEasy/issues/2056[#2056]: Replaced progress bar with general progress information for installing plugins in VSCode
* https://github.com/devonfw/IDEasy/issues/1659[#1659]: Abort runTool with warning when global tool installer runs in background
* https://github.com/devonfw/IDEasy/issues/1720[#1720]: Integrate SoapUI
* https://github.com/devonfw/IDEasy/issues/1167[#1167]: Automatic project import for vs code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please move this entry up to the latest release.

@hohwille hohwille added this to the release:2026.08.002 milestone Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request repository Commandlet to clone, build or import git repositories vscode Microsoft visual studio code

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

Automatic project import for VSCode

5 participants