GithubHelp home page GithubHelp logo

swift.vim's People

Contributors

aclissold avatar andrewsb avatar aymanbagabas avatar codelahoma avatar dduan avatar dirtyhabits97 avatar gfontenot avatar harlanhaskins avatar kattrali avatar keith avatar kylef avatar manenko avatar mindtooth avatar mossheim avatar raimon49 avatar reflejo avatar samsymons avatar tokorom avatar yasumoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift.vim's Issues

indirect modifier

The second indirect is a valid variable name which should not be rendered as a keyword.
screen shot 2015-12-28 at 2 58 37 pm

neocomplcache compatability

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?

Interpolated string issue

Currently this isn't highlighted correctly:

                return addressParts.count == 2 ? addressParts[1] : "\(addressParts[1]), \(addressParts[2])"

If you place a space after the first " it is fixed. It also affects the next lines. Maybe swiftInterpolatedWrapper should be oneline

screen shot 2016-02-08 at 14 56 47

Indent problem on closing braces

If I use = to auto indent this block:

    override func loadView() {
        super.loadView()
    }

it turns into:

    override func loadView() {
        super.loadView()
        }

Brackets in strings affect indent

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.

indent on multiline declarations

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.

Include all swift files in the current project

Based on the conversation from #35

Here's my quick checklist for getting this in:

  • Use git ls-files in projects versioned by git (determine with something like this)
  • Fallback to vim's glob() or find
  • Allow users to provide a command for this (not dependent on git vs non-git, that would be up to them)
  • Allow users to provide an array of directories to exclude (default to something like ["Tests", "Specs"])
  • Automatically update the file list on BufNewFile
  • Provide a command for updating the file list if the file was created elsewhere
  • Allow users to fallback to the single file testing

Add new comment modifiers

Swift 3.0 is adding some comment identifiers. They can be found here we should add these to highlight correctly in swift.vim

Incorrect trailing closure body indentation

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?")
}

Modules from `.swift` files in the same target aren't recognized.

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?

Multiline function indentation conflicts with closure syntax

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?

Unknown function: shiftwidth

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.

Highlighting issue in arrays

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)),
    ]
)

Use 4-space indentation

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."

Lines with a closing bracket deindented prematurely

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])

? and ! included as keywords makes optional type names not searchable easily

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?

Block comments aren't highlighted correctly

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

Figure out a better way to indent

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.

Curly braces inside strings affect indentation

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)!
}

Indent on multiline function declaration

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)")
                                                        }

Complex numbers

Swift can have numbers like:

5e-2

Need to adjust the highlighting for this.

Also:

0xa3p2

Support Ctags

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
\ }

Here is how it looks like:
screen shot 2015-12-08 at 11 12 37 am

Cases in switch statements don't re-indent properly

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: //
}

Multiline guard indentation

Currently there's a problem with multiline guards (and if lets) where the cases on their own lines will not be indented correctly. See an example here:

guard let path = NSBundle.mainBundle().pathForResource(imageName, ofType: "png"),
let data = NSData(contentsOfFile: path),
let data = NSData(contentsOfFile: path) else
{
}

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.

Highlighting strings while typing

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 :(

Closing braces should automatically unindent

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)

Indentation is way off

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())
      }
  }
  }
}
}

Basic indentation issue

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

Multiple protocols

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.

Installation instructions

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.