google / google/vim-codefmt

Consider a more imperative formatter API

Ouverte
#14 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Vim Script
Étoiles
1.1k
Forks
102
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

``` VimL
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

``` VimL
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.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par examiner les implémentations existantes de FormatRange et la manière dont codefmt les invoque ; aucun fichier ni test spécifique n’est nommé. Évaluez les opérations proposées de formattable, notamment GetLines, SetLines, SetCursor et AddError, au regard du traitement des plages et du comportement de quickfix. La tâche est terminée lorsqu’un design d’API est convenu et qu’un chemin de migration pour les formateurs est identifié.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
vim
Domaine
tooling
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.