LuaLS / LuaLS/lua-language-server

feature request: refactor to expand and collapse expressions

Đang mở
#2,833 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feat/diagnostics
Ngôn ngữ chính
Lua
Star
4.4k
Fork
442
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Issue không nêu tên tệp, bài kiểm thử hoặc điểm vào nào. Hãy bắt đầu bằng cách lập bản đồ phần triển khai refactoring hoặc code-action của language server, rồi xác định cách đặc tả và kiểm thử việc phân tích phạm vi, các lời nhắc đặt tên, việc mở rộng và các phép biến đổi có thể hoàn tác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
lua
Lĩnh vực
devtools
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.