Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bpeabody opened this issue Jan 12, 2015 · 15 comments
Closed

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

bpeabody opened this issue Jan 12, 2015 · 15 comments

Comments

@bpeabody
Copy link

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?

@keith
Copy link
Owner

keith commented Jan 12, 2015

I assume you're referring to the syntastic checker here. The checker just runs swiftc as seen here. If you wanted to get this multi-file behavior you'd have to pass some more flags to the checker through syntastic. I'm happy to make any changes necessary for that but you'll have to check the syntastic docs on how to get it working.

@bpeabody
Copy link
Author

Yes, that's correct. Let me see if I can get it working and I'll submit a pull request if I succeed.

@keith
Copy link
Owner

keith commented Jan 12, 2015

Awesome thanks!

@keith keith closed this as completed Jan 12, 2015
@malkomalko
Copy link

Did any of you figure this out? I know I have to add let g:syntastic_swift_swift_args="" to my vim config, but I can't quite figure out what the extra args should be. I took an output from an xcodebuild to try to figure out what args to send, but I haven't had any luck yet.

Cheers

@keith
Copy link
Owner

keith commented Mar 14, 2015

Based on this post swiftc program just expects a space delimited list of filenames to link. If you can figure out how to make it take *.swift you could probably solve this problem. The easy but crappy way to do this would be to use glob("*.swift") when you launch vim and set the results (with some string manipulation) to g:syntastic_swift_swift_args. This wouldn't work as you added files without reopening vim or writing a function to do this. (Another, better, idea would be to use git ls-files *.swift and pass that through).

@malkomalko
Copy link

With a lot of files, wouldn't the command line be too long? I wonder how swift deals with that when you have let's say 100 swift files.

@keith
Copy link
Owner

keith commented Mar 14, 2015

Interesting. Not sure.

Keith Smiley

On Mar 14, 2015, at 11:46, Robert Malko notifications@github.com wrote:

With a lot of files, wouldn't the command line be too long? I wonder how swift deals with that when you have let's say 100 swift files.


Reply to this email directly or view it on GitHub.

@malkomalko
Copy link

Instead of using swiftc, it might be a better idea to use swift -frontend -c as you have more options. It looks like one flag that xcodebuild uses is -primary-file which you would set to the current file, and the rest of the args would be the rest of the swift files.

@keith
Copy link
Owner

keith commented Mar 14, 2015

I feel like you'd still end up with the same problems we've mentioned.

@malkomalko
Copy link

The git ls-files *.swift with a custom function is a good idea. I just created a custom vim function that gets run on au BufWritePost *.swift call SwiftFiles(). If it's good enough for xcodebuild, it's good enough for me. You could even use glob("**/*.swift") like you said instead of git-files so you didn't have to add the file to git first. I think that's probably going to be the only option, and I don't think that's terrible.

@bpeabody
Copy link
Author

I did spend some time on this, but got distracted before I gave up. I think there are good clues to be had by looking at the build logs from Xcode itself. It does appear to passing all required files as arguments on the command line to swiftc.

git ls-files or similar find-based solution would probably work. I guess an ideal solution would generate the list based on inspection of the Xcode project files.

@malkomalko
Copy link

Updated my branch with commit at malkomalko@9abee95

fun! SwiftFiles()
  let files=glob('**/*.swift', 1, 1)
  let files=filter(files, 'v:val !~ "Tests/"')
  let files=filter(files, 'v:val !~ "' . @% . '"')
  let g:syntastic_swift_swift_post_args=join(files, ' ')
endfun

au BufWritePost *.swift call SwiftFiles()

In action: http://malkocasts.com/2T1f2R0w1I2u

As per @bpeabody's suggestion, I think you could easily do something where you parse the xcodeproj file to pull out a smarter list of swift source files, but this is good enough for me right now.

@keith
Copy link
Owner

keith commented Mar 15, 2015

I only see the 1 commit which doesn't include any other files besides the current one?

@malkomalko
Copy link

I didn't know if you wanted to include the swift files function in the plugin so I just updated the checker. Thoughts?

@keith
Copy link
Owner

keith commented Mar 15, 2015

Definitely. Opened an issue with the features I think are the MVP for this: #38 I could definitely be convinced otherwise though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants