LuaLS / LuaLS/lua-language-server

feature request: refactor to expand and collapse expressions

未关闭
#2,833 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feat/diagnostics
主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

It would be nice to be able to pull out repeated expressions or expand an expression on demand.
So one could jump back and forth between for example:

function love.draw()
    local w, h = love.graphics.getDimensions()
    love.graphics.setColor(1, 0, 0)
    love.graphics.circle('fill', 50, 50, 22)
    love.graphics.setColor(1, 1, 0)
    love.graphics.circle('fill', 50, 100, 22)
    love.graphics.setColor(0, 1, 0)
    love.graphics.circle('fill', 50, 150, 22)
end

and

local g = love.graphics

function love.draw()
    local w, h = g.getDimensions()
    g.setColor(1, 0, 0)
    g.circle('fill', 50, 50, 22)
    g.setColor(1, 1, 0)
    g.circle('fill', 50, 100, 22)
    g.setColor(0, 1, 0)
    g.circle('fill', 50, 150, 22)
end

It would also be nice to do this for local variables, so that the change is only applied where all the nessecary variables are visible (i.e. for required modules within a scope or long paths in arguments), so one can easily switch between

local function compileInfo(project)
    return {
        root = project.main,
        compiler = project.conf.toolchain == 'gnu' and 'gcc'
            or project.conf.toolchain == 'windows' and 'msvc'
            or project.conf.toolchain == 'clang' and 'clang'
    }
end

and

local function compileInfo(project)
    local c = project.conf
    return {
        root = project.main,
        compiler = c.toolchain == 'gnu' and 'gcc'
            or c.toolchain == 'windows' and 'msvc'
            or c.toolchain == 'clang' and 'clang'
    }
end

or

local function compileInfo(project)
    local t = project.conf.toolchain
    return {
        root = project.main,
        compiler = t == 'gnu' and 'gcc'
            or t == 'windows' and 'msvc'
            or t == 'clang' and 'clang'
	}
end

This is most usefull for long namespaced paths, but it may also be usefull to extract out some repeated constants or function calls and expand them again, so one can switch between:

local function copy(src, dst)
    for f in lfs.dir(src) do
        local src = io.open(src..package.config:sub(1, 1)..f, "rb")
        local dst = io.open(dst..package.config:sub(1, 1)..f, "wb")
    end
end

and

local DIR_SEP = package.config:sub(1, 1)

local function copy(src, dst)
    for f in lfs.dir(src) do
        local src = io.open(src..DIR_SEP..f, "rb")
        local dst = io.open(dst..DIR_SEP..f, "wb")
    end
end

Ideally one could chose the name of the pulled out expression via an prompt.

It's a long time since I had a good look at your codebase, so I wouldn't know where to start if I wanted to implement such a feature myself. I might be willing to try, if someone gives me a few pointers though.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

该 issue 未指明文件、测试或入口点。首先梳理 language server 的重构或 code-action 实现,并确定应如何规定和测试作用域分析、命名提示、展开以及可撤销的变换。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。