Skip to content

#1167: automatic project import vscode - #2263

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

#1167: automatic project import vscode#2263
QuangAnhLe wants to merge 12 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 32835932971

Coverage increased (+0.008%) to 73.663%

Details

  • Coverage increased (+0.008%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 20 coverage regressions across 3 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

20 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
com/devonfw/tools/ide/tool/ide/IdeToolCommandlet.java 15 86.36%
com/devonfw/tools/ide/tool/vscode/Vscode.java 4 86.67%
com/devonfw/tools/ide/version/VersionSegment.java 1 91.08%

Coverage Stats

Coverage Status
Relevant Lines: 18082
Covered Lines: 13927
Line Coverage: 77.02%
Relevant Branches: 8030
Covered Branches: 5308
Branch Coverage: 66.1%
Branches in Coverage %: Yes
Coverage Strength: 3.28 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hi @hohwille

Manual test for #1167 — result: no-op is the correct implementation

Manual test setup (as suggested in the issue):

  1. Created a full mirror backup of workspaces/main/.vscode (user-data-dir + settings.json, ~1.3 GB).
  2. Created a brand-new Maven project (test_mvn, minimal pom.xml + one class) that VSCode had never seen.
  3. Started the IDEasy-managed VSCode instance (ide vscode, workspace main).
  4. Recursively diffed the backup against the live .vscode state after the import completed.

Observation: No manual "import" step exists in VSCode. The Java language server (redhat.java / Eclipse m2e) automatically detected test_mvn/pom.xml during workspace scan at startup and imported it as a Maven project. No CLI feature or menu action is required (and none exists) — confirming the issue author's note that no VSCode CLI feature can archive this.

Diff result — what "import" actually writes:

  • All project state is created by the language server inside VSCode's user-data-dir, e.g. .userdata/User/workspaceStorage//redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/test-mvn/ containing .project (with maven2Nature/maven2Builder), .classpath (all entries maven.pomderived=true), .location, compiler/m2e prefs, plus m2e lifecycle/container state and JDT indexes.

  • Nothing is written to .vscode/settings.json or any other IDEasy-managed workspace file. The only workspace-level VSCode setting involved in Java project handling (java.jdt.ls.java.home for the language-server JDK) is already delivered by the workspace update template, independently of project import.

Conclusion / rationale for the no-op implementation:

  • Unlike IntelliJ (which reads per-project configuration from .idea/ files that IDEasy must create/merge), VSCode's import mechanism is fully autonomous inside the language server; there is no IDEasy-controlled file to apply, no CLI command to invoke, and no per-project setting that the IDE consumes.

  • Merging a template into .vscode/settings.json would produce a file that VSCode does not use for importing projects, i.e. it would not achieve the issue's goal ("project is recognized and built by VSCode") and could not be verified as done.

  • Therefore Vscode#importRepository correctly does not merge any template; it logs a success message stating that VSCode imports Maven/Gradle projects automatically, so the "Importing repository … into vscode" step completes cleanly when import=vscode is configured. The centralized import logic in IdeToolCommandlet remains and continues to serve IntelliJ.

Could you please confirm that this solution is acceptable, or let me know if you expect different behavior for the VS Code import step?

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