Skip to content

Commit

Permalink
lsp: Clean workspace root from eval errors (#1028)
Browse files Browse the repository at this point in the history
Fixes #1008

Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 authored Aug 29, 2024
1 parent ebdc067 commit b1551ee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,11 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) {
if err != nil {
fmt.Fprintf(os.Stderr, "failed to evaluate workspace path: %v\n", err)

cleanedMessage := strings.Replace(err.Error(), l.workspaceRootURI+"/", "", 1)

err := l.conn.Notify(ctx, "window/showMessage", types.ShowMessageParams{
Type: 1, // error
Message: err.Error(),
Message: cleanedMessage,
})
if err != nil {
l.logError(fmt.Errorf("failed to notify client of eval error: %w", err))
Expand Down Expand Up @@ -1744,7 +1746,10 @@ func (l *LanguageServer) handleInitialize(
return nil, fmt.Errorf("failed to unmarshal params: %w", err)
}

l.workspaceRootURI = params.RootURI
// params.RootURI is not expected to have a trailing slash, but if one is
// present it will be removed for consistency.
l.workspaceRootURI = strings.TrimSuffix(params.RootURI, string(os.PathSeparator))

l.clientIdentifier = clients.DetermineClientIdentifier(params.ClientInfo.Name)

if l.clientIdentifier == clients.IdentifierGeneric {
Expand Down

0 comments on commit b1551ee

Please sign in to comment.