Consider a more imperative formatter API

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

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

Đánh giá

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

Hướng nghiên cứu

Bắt đầu bằng việc xem xét các triển khai FormatRange hiện có và cách codefmt gọi chúng; không có tệp hoặc kiểm thử cụ thể nào được nêu tên. Đánh giá các thao tác formattable được đề xuất, bao gồm GetLines, SetLines, SetCursor và AddError, trong mối tương quan với việc xử lý phạm vi và hành vi quickfix. Hoàn thành nghĩa là đã thống nhất thiết kế API và xác định được lộ trình di chuyển cho các formatter.

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

Mô tả

enhancement

Formatters right now take a range and modify the buffer as a side-effect, e.g.

function someformatter.FormatRange(startline, endline) abort
  let l:lines = getline(1, line('$'))
  let l:result = maktaba#syscall#Create(…).WithStdin(join(l:lines, "\n")).Call()
  call maktaba#buffer#Overwrite(1, line('$'), split(l:result.stdout, "\n"))
endfunction

codefmt itself has very little insight into what the formatter is doing, and the amount of boilerplate is also a little annoying. Things can get weird if e.g. FormatRange is called multiple times to process multiple ranges, especially with formatters that try to populate errors into the quickfix list.

A different approach would be to pass a codefmt handle and implement formatter operations in terms of that handle, like

  • formattable.GetLines([start], [end])
  • formattable.SetLines({lines})
  • formattable.SetLines({start}, {end}, {lines})
  • formattable.SetCursor({row}, {col})
  • formattable.AddError({error}, [row], [col])

A simple formatter would look like

function someformatter.FormatRange(startline, endline, formattable) abort
  let l:input = join(a:formattable.GetLines(), "\n")
  let l:result = maktaba#syscall#Create(…).WithStdin(l:input).Call()
  call a:formattable.SetLines(l:result.stdout)
endfunction

Some advantages are that it can make some formatting operations more convenient and anti-patterns like overwriting files on disk less natural. If we run into wonkiness as we enable fancy features like format-changed-lines-on-save (multiple ranges), it could help solve issues like that, too.

Ngôn ngữ chính
Vim Script
Star
1.1k
Fork
102
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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.

Issue khác của google/vim-codefmt

Tất cả issue của google/vim-codefmt

Issue tương tự

Thêm issue về DevTools

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.