keith / swift.vim Goto Github PK
View Code? Open in Web Editor NEWVim runtime files for Swift
License: MIT License
Vim runtime files for Swift
License: MIT License
See https://github.com/kylef/PathKit/blob/master/PathKit/PathKit.swift#L180
public var `extension`: String?
When I first enter insert mode on a Swift file, I get an error from neocomplcache:
Another plugin set completefunc! Disabled neocomplcache
Any way to disable this / use my own completion?
If I use =
to auto indent this block:
override func loadView() {
super.loadView()
}
it turns into:
override func loadView() {
super.loadView()
}
Related: #58
string.rangeOfString("^/Date\\(")
The (
in this string breaks the indent on the next line. Like the referenced issue we'll need to check that the bracket is not in a comment or a string.
The following will break syntax highlighting as of right now:
"\\".uppercaseString
Auto-indenting this block:
let foo = CGRectMake(0, 0,
200, 400)
results in:
foo = CGRectMake(0, 0,
200, 400)
And if I was typing this out, hitting enter after 0,
would put me at the same indent level. Instead it should be indented by 1 like the original block above.
If I fix the indentation manually for the 2nd line, then hit enter at end of line, the next line is at the same indentation instead of going back out. It should detect that it's the end of a statement and go back to the same indentation as the start of the statement.
Based on the conversation from #35
Here's my quick checklist for getting this in:
git ls-files
in projects versioned by git (determine with something like this)glob()
or find
["Tests", "Specs"]
)BufNewFile
Swift 3.0 is adding some comment identifiers. They can be found here we should add these to highlight correctly in swift.vim
Something to do with trailing closures where the previous parameter was also a closure?
UIView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: {
view.backgroundColor = UIColor.redColor()
}) { finished in
print("indent?")
}
I apologize in advance if I'm missing something obvious, but I've been unable to figure this out on my own. If, for example, I have:
// foo.swift
class Foo {}
and
// bar.swift
let foo = Foo()
where foo.swift
and bar.swift
are in the same target, it complains that it doesn't recognize Foo
when Foo
is used in bar.swift
. How do I configure this plugin to see other modules in the same target?
So, a fun task is running gg=G on every Swift file and seeing what happens…
UIView.animateWithDuration(0.4, animations: {
view.backgroundColor = UIColor.redColor()
})
I see this style was decided on in #19, but personally I prefer wrapping multiline function calls like this:
someFunction(with: 1, a: 2, lot: 3, of: 4, parameters: 5,
objectiveCPrefersLengthyExternalParameterNames: true)
because it's lessing jarring to my eyes, and also because Objective-C APIs don't play well with the "Python" style. Would this fix the closure issue?
I'm using latest version of the plugin (commit hash: 3ef5669).
In my environment, indentation settings of swift.vim do not work entirely.
When I call SwiftIndent
function directory, it causes an error like below.
:echo SwiftIndent(v:lnum)
Error detected while processing function SwiftIndent:
line 49:
E117: Unknown function: shiftwidth
E15: Invalid expression: previousIndent + shiftwidth()
0
When I replace the whole function calls like shiftwidth()
to value reference &l:shiftwidth
, indentation setting works fine.
Is it the problem of my environment?
Thanks in advance.
Example of current behaviour:
let dict = [
"hello": "world",
"foo": [
"bar": "baz",
] // => should decrease indent
]
let ary = [
"foo",
"bar",
"baz",
] // => should decrease indent
This statement currently has pretty funky highlighting:
import PackageDescription
let package = Package(
name: "hypem",
dependencies: [
.Package(url: "https://github.com/lyft/mapper.git", versions: Version(2,0,0)..<Version(2,2,0)),
.Package(url: "https://github.com/Alamofire/Alamofire.git", versions: Version(2,0,0)..<Version(2,2,0)),
]
)
It looks like fdb1ac8, which intended to fix auto-indentation, also decided to make 2 spaces the default. Was this intentional? I saw that this was decided against in issue #17, and 4 is a much less polarizing default than 2. Plus, the style guide mentioned in that issue is "centered on readability for print and the web."
Actual:
self.init(className: "Item", dictionary: [
"identifier": item.identifier,
"title": item.title,
"link": item.link,
"date": item.date,
"summary": item.summary])
Expected:
self.init(className: "Item", dictionary: [
"identifier": item.identifier,
"title": item.title,
"link": item.link,
"date": item.date,
"summary": item.summary])
Following this Swift style guide I'd like to use 2 space indentation. Could this be configurable?
ftplugin/swift.vim includes ? and ! as keywords:
setlocal iskeyword+=?,!,@-@,#
which makes optional types different from the non-optional version. So if I place the cursor over UICollectionView in the line for v1 and hit keys like gd
, or *
, it doesn't match the lines for v2 and v3. Vice versa.
var v1: UICollectionView
var v2: UICollectionView?
var v3: UICollectionView!
Seems better to set keywords like so:
setlocal iskeyword+=@-@,#
Any reason why ! and ? are included?
Hi, while using Vim in Terminal I see block comments not being highlighted correctly.
For example with code like the one in the following code snippet
/* Comment 1 */
func f(i: Int) -> Int {
/* Comment 2 */
}
Comment 1 is highlighted correctly, while Comment 2 is not.
Maybe it has something to do with my vimrc?
Thanks very much
The current indentation method isn't scaling well. There are too many cases which have become impossible to test. I need to isolate what can be passed off to cident
and do that. I should also spend some time looking through some other indent files in $VIMRUNTIME
to see how they handle this.
Here's a simple example showing this, chuck the following piece of code inside a vim session and select it all and then re-ident (=).
public struct Lexer {
public let templateString:String
let regex = NSRegularExpression(pattern: "(\\{\\{.*?\\}\\}|\\{%.*?%\\}|\\{#.*?#\\})", options: nil, error: nil)!
}
Afterwards it looks something like:
public struct Lexer {
public let templateString:String
let regex = NSRegularExpression(pattern: "(\\{\\{.*?\\}\\}|\\{%.*?%\\}|\\{#.*?#\\})", options: nil, error: nil)!
}
Try indenting:
override func observeValueForKeyPath(keyPath: String!,
ofObject object: AnyObject!,
change: NSDictionary!,
context: CMutableVoidPointer) {
println("CHANGE OBSERVED: \(change)")
}
Result:
override func observeValueForKeyPath(keyPath: String!,
ofObject object: AnyObject!,
change: NSDictionary!,
context: CMutableVoidPointer) {
println("CHANGE OBSERVED: \(change)")
}
Swift can have numbers like:
5e-2
Need to adjust the highlighting for this.
Also:
0xa3p2
https://github.com/apple/swift/tree/master/utils/vim
I'm wondering what the difference between yours and the official one.
It'll be nice to set up ctags with this plugin. But I'm not familiar with Vim plugin dev.
Here is my .ctags
config:
--langdef=Swift
--langmap=Swift:+.swift
--regex-swift=/enum[ \t]+([^\{\}]+).*$/\1/n,enum,enums/
--regex-swift=/typealias[ \t]+([^:=]+).*$/\1/t,typealias,typealiases/
--regex-swift=/protocol[ \t]+([^:\{]+).*$/\1/p,protocol,protocols/
--regex-swift=/struct[ \t]+([^:\{]+).*$/\1/s,struct,structs/
--regex-swift=/class[ \t]+([^:\{]+).*$/\1/c,class,classes/
--regex-swift=/func[ \t]+([^\(\)]+)\([^\(\)]*\)/\1/f,function,functions/
--regex-swift=/(var|let)[ \t]+([^:=]+).*$/\2/v,variable,variables/
--regex-swift=/^[ \t]*extension[ \t]+([^:\{]+).*$/\1/e,extension,extensions/
And .vimrc
:
" tagbar
nmap <F8> :TagbarToggle<CR>
let g:tagbar_type_swift = {
\ 'ctagstype': 'swift',
\ 'kinds' : [
\ 'n:Enums',
\ 't:Typealiases',
\ 'p:Protocols',
\ 's:Structs',
\ 'c:Classes',
\ 'f:Functions',
\ 'v:Variables',
\ 'e:Extensions'
\ ],
\ 'sort' : 0
\ }
Seems like I missed this one before
The accepted style for switch statements in Swift is:
switch(foo) {
case bar: //
case baz: //
}
However, right now, swift.vim is not un-indenting the case statements, and you end up with
switch(foo) {
case bar: //
case baz: //
}
Currently there's a problem with multiline guards (and if let
s) where the cases on their own lines will not be indented correctly. See an example here:
swift.vim/example/example.swift
Lines 327 to 331 in 7d7c6e3
This is a hard problem. We can't only rely on the line above, or matching brackets/parens as we are everywhere else. Instead I guess we'll have to match multiple lines above, and find a guard/if. This will also have to handle the valid cases for closures in the statements such as:
guard let foo = bar.map({ $0.whatever }),
let ugh = vim.syntaxfiles {
I took a stab at this by matching a line ending with a comma above the current line, and the current line having an =
with:
previous =~ ",$" && line =~ '\v^s*(\w|\s)+\='
But this doesn't handle where
clauses, or statements that are over more than 2 lines.
The body's of doc comments aren't highlighted. swift.vim should highlight :param:
etc
When I'm typing a string in some Ruby code, the string is highlighted even if
I haven't put in the closing "
yet:
string = "this is a string
# ^^^^^^^^^^^^^^^^^ this is highlighted
However in Swift, there's no highlighting until after I complete the string:
let string = "this is a string
// ^^^^^^^^^^^^^^^^^ this is not highlighted
This, for example, makes it difficult to properly matching string interpolation delimiters unless you first close off the string:
let string = "\(interpolated)"
let string = "\(interpolated)
// ^^ ^ <= no highlighting :(
Similar to #40, but it should also unindent while you're typing :)
I haven't looked, but I bet there's examples online or in Vim syntax files of how to do this since so many languages behave this way already (e.g., Java)
Here are 2 examples, let's start with a simpler one:
import Cocoa
println("OHAI")
class Installer {
required init() {
println("hohoho")
}
}
Installer()
println("END")
As you type, indentation gets immediately wrong on required init
,. Even if you select all and +
, it stays screwed.
A more complex example is by pasting the sample code from Quick:
import Quick
import Nimble
print("hello")
class TableOfContentsSpec: QuickSpec {
override func spec() {
describe("the table of contents below") {
it("has everything you need to get started") {
let sections = TableOfContents().sections
expect(sections).to(contain("Quick: Examples and Example Groups"))
expect(sections).to(contain("Nimble: Assertions using expect(...).to"))
expect(sections).to(contain("How to Install Quick"))
}
context("if it doesn't have what you're looking for") {
it("needs to be updated") {
let you = You(awesome: true)
expect{you.submittedAnIssue}.toEventually(beTruthy())
}
}
}
}
}
Curly braces are not un-indenting correctly for me. It comes out like this:
if(true){
}else{
}
I would expect it to be like this
if(true){
}else{
}
I have tried enabling cindent, autoindent, and smartindent. Doesn't seem to have any effect
Having issues matching something like:
class Foo: UIViewController, UITableViewDataSource {
Where UITableViewDataSource
doesn't get matched.
I attempted to modify the regex of swiftTypeWrapper
but it ended up incorrectly highlighting:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
Where cellForRowAtIndexPath
was highlighted.
Hi,
Looks like you're done some pretty amazing work here. Some short installation instructions for those of us who aren't pros at vim or vim-plug would be very helpful.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.