Open dabrahams opened 1 year ago
Our lexer needs to analyze the type of tokens and required to parse both forward and backward, rather than just skipping forward. It also needs to parse various constructs other than types.
Hiding bodies would be useful, but why not just use hs-hide-all
or hs-hide-level
? Those functions can handle other types of blocks and parenthesis. For example, swift-hide-bodies
doesn't hide let
definitions in Parser.swift while hs-hide-level
handles parenthesized expressions well.
Besides, swift-hide-bodies
needs some improvements:
swift-skip-type-name
doesn't skip those types:
@A B
Int!
P & Q
some P
any P
(Int) async throws -> Int
`Int`
😊
swift-hide-bodies
mishandles:
class Foo {
func `deinit`(f: () -> Void) -> Void {
f()
}
}
let foo = Foo() // we can use bare keyword as identifier after dot. let x = foo.deinit { print("aaa") }
- `var` in `case` patterns:
```swift
if case var x: Int=1 {
print("aaa")
}
Note that swift-skip-type-name
thinks Int=1
is a type name.
swift-hide-doc-comment-detail
seems to be nice to incorporate. I'm not sure how to combine codes under Apache License v2.0 and GPLv3, though I know that Apache License v2.0 is compatible with GPLv3.
Other than that, Apple's swift-mode
seems to be less accurate while concise and efficient; it doesn't handle those constructs:
Multiline string literals:
let x = """
aaa " aaa
"""
let y = Foo()
Extended string literals: #"abc"def"#
String interpolations: "aaa \(/* " */ 1) bbb"
Regular expressions.
Nested multiline comments.
On Nov 19, 2022, at 2:31 AM, taku0 @.***> wrote:
Hiding bodies would be useful, but why not just use hs-hide-all or hs-hide-level?
hs-hide-all hides too much (the methods and properties of every type); I was unable to make hs-hide-level do anything useful in my Swift file.
Those functions can handle other types of blocks and parenthesis. For example, swift-hide-bodies doesn't hide let definitions in Parser.swift https://github.com/val-lang/val/blob/a4afd99/Sources/Compiler/Parse/Parser.swift while hs-hide-level handles parenthesized expressions well.
? let definitions don’t ever have bodies in Swift. A body is a block surrounded by braces at the top level of a declaration.
Hiding everything but the summary of doc comments can also be extremely useful.
I’m aware code hasn’t been updated in many years as Swift syntax has evolved, and if it or the features it implements are of no use to you, that’s perfectly fine with me. I just thought I’d offer.
Cheers, Dave
hs-hide-all hides too much (the methods and properties of every type); I was unable to make hs-hide-level do anything useful in my Swift file.
C-2 M-x hs-hide-level
at the beginning of the Parser.swift
will show you outline of the file.
? let definitions don’t ever have bodies in Swift. A body is a block surrounded by braces at the top level of a declaration.
Parser.swift
has many let bindings with large expression, that is, functionDecl
and followings. To grab the outline of the file, it should be hidden.
I was the primary developer of this file when I was on the Swift project, and there are some nice bits in there that might benefit your mode. In particular, the
-skip-
functions approximately parse swift pretty reliably and efficiently (I see you have your own code for that and I haven't tried to compare it, but the hangs withwhich-function
mode make me suspect you might want to try a different approach), and there are useful functions for folding away the details of files when you want to easily understand an API.I sucked those into my personal configuration so I could still use that functionality with your mode.
If there's any interest, I'm happy to help. OTOH, if you've already evaluated what's in there and decided none of it is useful, then, sorry for the noise!