Skip to content

Commit

Permalink
Add workspace folder type, and "support" that capability
Browse files Browse the repository at this point in the history
Ironic quotes on support since this seems to be a client feature
only, but I figured we'd still document that in the code rather
than elsewhere, for reference next time we look into that.

Next up to look into supporting this in the OPA VS Code extension.

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert committed Jan 18, 2025
1 parent 193224a commit 91f3f32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,18 @@ func (l *LanguageServer) handleInitialize(
Filters: []types.FileOperationFilter{regoFilter},
},
},
WorkspaceFolders: types.WorkspaceFoldersServerCapabilities{
// NOTE(anders): The language server protocol doesn't go into detail about what this is meant to
// entail, and there's nothing else in the request/response payloads that carry workspace folder
// information. The best source I've found on the this topic is this example repo from VS Code,
// where they have the client start one instance of the server per workspace folder:
// https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-multi-server-sample
// That seems like a reasonable approach to take, and means we won't have to deal with workspace
// folders throughout the rest of the codebase. But the quesstion then is — what is the point of
// this capability, and what does it mean to say we support it? Clearly we don't in the server as
// *there is no way* to support it here.
Supported: true,
},
},
InlayHintProvider: types.InlayHintOptions{
ResolveProvider: false,
Expand Down
9 changes: 7 additions & 2 deletions internal/lsp/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type InitializeParams struct {
RootPath string `json:"rootPath"`
RootURI string `json:"rootUri"`
Trace string `json:"trace"`
WorkspaceFolders []WorkspaceFolder `json:"workspaceFolders"`
WorkspaceFolders *[]WorkspaceFolder `json:"workspaceFolders"`
Capabilities ClientCapabilities `json:"capabilities"`
ProcessID int `json:"processId"`
}
Expand Down Expand Up @@ -175,8 +175,13 @@ type CompletionItemLabelDetails struct {
Detail string `json:"detail"`
}

type WorkspaceFoldersServerCapabilities struct {
Supported bool `json:"supported"`
}

type WorkspaceOptions struct {
FileOperations FileOperationsServerCapabilities `json:"fileOperations"`
FileOperations FileOperationsServerCapabilities `json:"fileOperations"`
WorkspaceFolders WorkspaceFoldersServerCapabilities `json:"workspaceFolders"`
}

type CodeActionOptions struct {
Expand Down

0 comments on commit 91f3f32

Please sign in to comment.