LuaLS / LuaLS/lua-language-server

"Expand Selection" doesn't expand to strings or scopes

Open
#3,455 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

I use VScode's "Expand Selection" command a lot to copy strings around, but when I try to use it on Lua strings, it expands the selection a lot more than just the string I'm on.

## Actual behavior

Suppose my cursor is inside the word example:

> hs.alert(prefix .. " an exam`|`ple string " .. suffix)

1st call to Expand Selection selects the word:

> hs.alert(prefix .. " an `example` string " .. suffix)

2nd call to Expand Selection selects everything between `()` instead of the full string:

> hs.alert(`prefix .. " an example string " .. suffix`)

## Expected behavior

2nd call to Expand Selection should select just the string:

> hs.alert(prefix .. `" an example string "` .. suffix)

In JavaScript, I noticed it even has two steps for the string, the inner part of the string, then the outer:

> alert(prefix + " an `example` string " + suffix)

> alert(prefix + "` an example string `" + suffix)

> alert(prefix + `" an example string "` + suffix)

That would also work!

## Similar scenarios

Scopes are also currently skipped:

> local myFunction = function () ret`|`urn true end

> local myFunction = function () `return` true end <- 1st call selects the word

> local myFunction = `function () return true end` <- expected: 2nd call selects the function scope

> `local myFunction = function () return true end` <- actual: 2nd call selects the line instead

Same for `Object.property`:

> Object.`property` = true

> `Object.property` = true <- expected

> `Object.property = true` <- actual

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Expand Selection implementation and any tests covering selection expansion; the issue does not name specific files or entry points. Reproduce the Lua string, function-scope, and Object.property examples, then add coverage showing that successive expansions select the expected constructs.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.