You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`LanguageClientImpl#createSettings()` which must return a Gson JsonObject of your configuration.
759
759
* or `LanguageClientImpl#findSettings(String section)` if you don't want to work with GSon JsonObject.
760
+
761
+
# Workspace Folders
762
+
763
+
LSP4IJ provides support for [workspace/workspaceFolders](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_workspaceFolders) to control which directories are sent to the language server as workspace roots
764
+
with [WorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/WorkspaceFolderStrategy.java) API.
765
+
766
+
## Default Behavior
767
+
768
+
By default, LSP4IJ uses the [ProjectWorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/ProjectWorkspaceFolderStrategy.java) which sends all project base directories as workspace folders during initialization.
769
+
770
+
## Workspace Folder Strategy
771
+
772
+
You can customize workspace folder discovery by using one of the built-in strategies, configuring a strategy with JSON, or implementing your own [WorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/WorkspaceFolderStrategy.java).
773
+
774
+
### Built-in Strategies
775
+
776
+
LSP4IJ provides several built-in strategies:
777
+
778
+
#### ProjectWorkspaceFolderStrategy (Default)
779
+
780
+
Uses the IntelliJ [ProjectWorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/ProjectWorkspaceFolderStrategy.java) project base directories as workspace folders. By default, all folders are sent during initialization.
You can extend the strategy to enable lazy loading, sending workspace folders progressively via `workspace/didChangeWorkspaceFolders` as files are opened:
This is useful for large projects where you want to avoid sending all workspace folders upfront.
809
+
810
+
#### SourceRootsWorkspaceFolderStrategy
811
+
812
+
Uses IntelliJ module [SourceRootsWorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/SourceRootsWorkspaceFolderStrategy.java) source roots as workspace folders. By default, all folders are sent during initialization.
813
+
814
+
Useful when you want to expose only source directories (not the entire project root) to the language server.
Use [MarkersWorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/MarkersWorkspaceFolderStrategy.java)
837
+
to discover workspace folders dynamically by walking up the directory tree looking for marker files.
838
+
Folders are discovered lazily as files are opened.
-**Python projects** with `pyproject.toml` or `setup.py`
850
+
-**Node.js projects** with multiple `package.json` files
851
+
852
+
For example, when opening `/monorepo/backend/src/app.py` with markers `["pyproject.toml"]`:
853
+
1. Checks `/monorepo/backend/src/` for `pyproject.toml`
854
+
2. Checks `/monorepo/backend/` for `pyproject.toml` ← **Found!**
855
+
3. Returns `/monorepo/backend/` as workspace folder
856
+
857
+
#### ConfigurableWorkspaceFolderStrategy
858
+
859
+
[ConfigurableWorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/ConfigurableWorkspaceFolderStrategy.java) is a flexible strategy that can be configured with JSON to support different root types, markers, and lazy loading options:
The [ConfigurableWorkspaceFolderStrategy](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/workspaceFolder/ConfigurableWorkspaceFolderStrategy.java) supports the following JSON configuration:
975
+
976
+
#### Root Type
977
+
978
+
Determines how workspace folders are discovered:
979
+
980
+
-**`PROJECT_BASE`** (default): Uses IntelliJ project base directories
981
+
-**`SOURCE_ROOTS`**: Uses module source roots
982
+
-**`NONE`**: No workspace folders
983
+
984
+
```json
985
+
{
986
+
"rootType": "SOURCE_ROOTS"
987
+
}
988
+
```
989
+
990
+
#### Marker-based Discovery
991
+
992
+
When `markers` is specified, LSP4IJ walks up the directory tree from each opened file looking for the specified marker files:
public @NotNullList<WorkspaceFolder>getInitialWorkspaceFolders(
1078
+
@NotNullProjectproject,
1079
+
@NotNullFileUriSupportfileUriSupport) {
1080
+
// Return folders to send during initialization
1081
+
List<WorkspaceFolder> folders =newArrayList<>();
1082
+
// ... custom logic ...
1083
+
return folders;
1084
+
}
1085
+
1086
+
@Override
1087
+
public @NullableWorkspaceFoldergetWorkspaceFolderForFile(
1088
+
@NotNullVirtualFilefile,
1089
+
@NotNullProjectproject,
1090
+
@NotNullFileUriSupportfileUriSupport) {
1091
+
// Return the workspace folder for a given file
1092
+
// ... custom logic ...
1093
+
returnnull;
1094
+
}
1095
+
1096
+
@Override
1097
+
publicbooleansendAllFoldersOnInitialization() {
1098
+
// Return true to send all folders at init, false for lazy loading
1099
+
returntrue;
1100
+
}
1101
+
}
1102
+
```
1103
+
1104
+
## User-Defined Language Server Configuration
1105
+
1106
+
For user-defined language servers, workspace folder configuration can be specified in the `workspaceFolderSettings.json` template file or configured in the UI:
0 commit comments