fix(ast): preserve emptyline before comment#3
Conversation
e75bd0a to
74341aa
Compare
|
@aldum I've completely changed the PR logic to the cleaner and more predictable approach. Apologies for the inconvenience! |
aldum
left a comment
There was a problem hiding this comment.
I feel no confidence that I can game all of this out in my head, please add unit tests that demonstrate this code working as intended.
|
|
||
| ---------------------------------------------------------------- | ||
| --- Reset last non-empty source line to the current position | ||
| --- @param pos table? |
There was a problem hiding this comment.
Can we be more specific about this type? If it's not some existing class, at least a structural type alias would be useful.
There was a problem hiding this comment.
I would ask for your help/recommendation here then.
In practice it's ad-hoc polymorphic, accepting a union of two types.
Annotation problem is that one of them is not defined explicitl, and for another one I just cannot find type definition within sane time:
clasttable as built on line 402 simply does not have type definition or aliasnode.lineinfo.firstornode.lineinfo.lastcould be passed -- but I am not sure where the type is defined
There was a problem hiding this comment.
lineinfo is defined here in turn referencing position here
clast is a value, it's type is basically Cursor, but that's in compy, so metalua strictly speaking doesn't know about it.
An ad-hoc union works here, as in
---- @param pos position|{l : integer}Long term, probably this should be refactored to use a position type, or a new PositionBase (equivalent to Cursor). There's some impedance mismatch because metalua originally had nothing for types (this language server we use might have not even existed yet).
Just added and pushed (see last commit), would love to know your thoughts |
| @@ -1,3 +1,5 @@ | |||
| local fmt=string.format | |||
There was a problem hiding this comment.
Done, for this file only (several other changed, such as ast_to_src itself and spec examples, I did not risk lintering, as they seem to purposefully ignore double-quoting standard for the sake of clarity, and maybe few other conventions too).
For convenience, I've added also added .editorconfig and justfile lint directive (using stylua just because why not). I do not insist them to be a freezed canon, rather some reasonable baseline to start from.
Now AST converter tracks emptyline sequences in the source, and emits a single emptyline into result whenever such a sequence precedes the comment preceding the node
* new test suite added for emptylines manipulation * spec script adjusted to inject tags at suite and case levels * justfile enhanced to allow per-tag testing without nodemon
For now, stylua is used as ad-hoc default, it can be changed later
Now AST converter tracks emptyline sequences in the source,
and emits a single emptyline into result
whenever such a sequence precedes the comment preceding the node
(NOTE: initial version of this PR was ditched and it was redone from scratch)