Hacker News new | ask | show | jobs
by firasd 7 hours ago
LSPs don't really do this. They're like a better way to grep for something (so they do address the previous thing I said about listing all function names etc.) But they often don't say (depending on the particular LSP setup etc) this function ends at this char and they definitely don't then provide the text editing tool
1 comments

This is not accurate. Most LSPs do provide text editing tools, which the Language Server Protocol calls "code actions". These actions do things like: reorganizing imports, expanding macros, extracting a selection into a function, or converting one type of control flow into another (e.g. if to match). Common LSPs, like rust-analyzer and Ruff (Python) support code actions. Editors also expose code actions: Zed, for instance, exposes actions under the default keymap with the binding Command + .

source: https://microsoft.github.io/language-server-protocol/specifi... and https://microsoft.github.io/language-server-protocol/specifi...

Come on what are we talking about. Ruff is a linter. Can you show me any LSP server that can move an arbitrary function from file1.ts to file2.ts based on calling it on the command line?
They're not command line applications, they use JSON-RPC inline, and it's an interactive flow, so you need the client to actually persist state.

So what you'd see in the LLM traces, for example, is a couple back-and-forths using JSON-RPC. It absolutely works at the moment, and claude code will happily use it if everything is set up correctly, just tested it using https://github.com/typescript-language-server/typescript-lan...

What did you test exactly?

Look what I’m asking for is not complicated

Node cutpaste.js inputpath startcharnum endcharnum outputpath startcharnum

I was just using it as an example of how dropping claude / gpt in a Linux shell and saying good luck and then giving interviews about spawning sub agents seems to overlook basic text editing primitives

But if you managed to move an arbitrary char range from one file to another using Claude Code talking to the TS LSP server let me know that would be enlightening.

The relevant points have already been made: (1) LSP is a JSON-RPC protocol, not a CLI app, and (2) Language Servers that implement LSP often utilize AST manipulation, even the resultant manipulations are exposed to the client via character ranges.

Still, these links may be of interest:

TypeScript’s language-service implementation of the “Move to file” refactor: https://github.com/microsoft/TypeScript/blob/main/src/servic...

Documentation for how `typescript-language-server` exposes that refactor as an opt-in code action: https://github.com/typescript-language-server/typescript-lan...

`ast-grep`, an AST-based search and transformation tool that may be closer in spirit to the cli functionality you describe, albeit more general-purpose: https://github.com/ast-grep/ast-grep

No, not an arbitrary character range, it's quite a lot smarter than that. It's an AST transformation - it takes the parsed tree out and puts it in another file and updates any imports that refer to the prior function to the new location. That all happens in the LSP side, not the LLM side, so it's deterministic. You can look at the source code for the LSP yourself.
I've had decent results telling agents to use emacs for structural editing operations. Pretty rare that I need to move a function across files verbatim but that should only be a few extra lines of elisp.
not sure if Go pls supports moving between files, but it does have some sophisticated edit features

https://go.dev/gopls/features/transformation

it does look to have a method for moving a function to a new file

I give my agent access to go pls and find it overall beneficial, based on vibes eval. Its way easier to ask LSP everywhere a function or field is used versus grep, saves a lot of tokens