Skip to content

feat(lsp): fixing LspToPosition via clamping and moving it to helper - #2700

Open
gat0sy wants to merge 1 commit into
Acode-Foundation:mainfrom
gat0sy:feat/lsp-core
Open

feat(lsp): fixing LspToPosition via clamping and moving it to helper#2700
gat0sy wants to merge 1 commit into
Acode-Foundation:mainfrom
gat0sy:feat/lsp-core

Conversation

@gat0sy

@gat0sy gat0sy commented Aug 8, 2026

Copy link
Copy Markdown

Fix lspPositionToOffset when LSP servers return EOF positions one line past the document via clamping

Extract lspPositionToOffset() and applyTextEdits() into a shared helper so clientManager and transport use the same bounds-safe logic of the new lspPositionToOffset

Send workspaceFolders when rootUri is available

Declare missing applyEdit, workspaceFolders, and code action resolve capabilities

Re-send workspace/didChangeConfiguration after initialization

Normalize SFTP URIs before sending them to LSP servers ( Assuming the LSP runs on the same machine as the sftp directory )

These fixes improve compatibility with servers that rely on workspace folders, applyEdit, resolvable code actions, post-init configuration, or full-document edits. They may need some polishing.

Note: CodeActions feature times out if more than one lsp are running at the same time when using the built-In LSPs

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR centralizes bounds-safe LSP text-edit application and expands initialization, workspace, configuration, URI-normalization, and workspace-edit support. The workspace-edit client-selection fix remains broken because its helper references an out-of-scope server and can still fall back to an unrelated plugin.

  • Adds clamped LSP position conversion and shared text-edit application.
  • Adds workspace folders and additional advertised client capabilities.
  • Handles server-pushed workspace edits and explicitly rejects unsupported resource operations.
  • Re-sends configuration after initialization and normalizes SFTP document URIs.
  • Adds an idle grace period before disposing clients.

Confidence Score: 3/5

The PR is not safe to merge because workspace edits currently fail on the out-of-scope server reference and can still be mapped through the wrong client after that is corrected.

The module-level workspace-edit helper evaluates server.id without receiving server, causing requests to return an internal error; its fallback also selects an unrelated plugin when the requesting client's plugin is absent.

Files Needing Attention: src/cm/lsp/transport.ts

Important Files Changed

Filename Overview
src/cm/lsp/transport.ts Adds workspace/applyEdit handling, but the helper references an out-of-scope server and its fallback preserves the wrong-client mapping failure.
src/cm/lsp/textEditUtils.ts Extracts shared bounds-safe LSP position conversion and text-edit application.
src/cm/lsp/clientManager.ts Adds workspace initialization capabilities, configuration resend, URI normalization, shared edit handling, and delayed idle disposal.

Sequence Diagram

sequenceDiagram
  participant Server as Requesting LSP server
  participant Transport
  participant Workspace
  participant View as Target EditorView
  participant Other as Unrelated LSP plugin
  Server->>Transport: workspace/applyEdit
  Transport->>Workspace: getFile/displayFile(uri)
  Workspace-->>Transport: target view
  Transport->>View: getAll plugins
  Transport->>Transport: evaluate server.id
  alt server identifier is available
    alt requesting server plugin exists
      View-->>Transport: matching plugin
    else requesting server plugin missing
      View-->>Transport: allPlugins[0]
      Transport->>Other: map positions and apply edits
    end
  else server is out of scope
    Transport-->>Server: applied false / internal error
  end
Loading

Reviews (2): Last reviewed commit: "feat(lsp): fixing LspToPosition adding a..." | Re-trigger Greptile

Comment thread src/cm/lsp/transport.ts Outdated
Comment thread src/cm/lsp/transport.ts Outdated
LspToPosition threw range error on format error.
We attempt to fix it here with by clamping so we get the correct line count between the client and server.

applyTextEdit as also been extracted so both transport and client manager can import it from the helper.
@bajrangCoder

This comment was marked as outdated.

Comment thread src/cm/lsp/transport.ts
Comment on lines +261 to +266
const plugin =
allPlugins.find(
(p) => (p.client as {
__acodeServerId?: string
}).__acodeServerId === server.id,
) ?? allPlugins[0];

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.

P1 Wrong-client fallback remains

When the target view lacks the plugin belonging to the requesting server, this fallback selects allPlugins[0], causing the edit to be mapped through another client's synchronized document and pending changes and therefore target incorrect offsets.

Knowledge Base Used: LSP Integration

Comment thread src/cm/lsp/transport.ts
Comment on lines +263 to +265
(p) => (p.client as {
__acodeServerId?: string
}).__acodeServerId === server.id,

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.

P1 Undefined server breaks edits

When workspace/applyEdit reaches this module-level helper, server is not in scope, so evaluating server.id throws and the handler returns an internal-error response without applying the workspace edit.

Knowledge Base Used: LSP Integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants