GithubHelp home page GithubHelp logo

Comments (12)

keith avatar keith commented on June 2, 2024

Definitely possible, the syntax checkers checked in to this repo currently only support swiftpm since that's such a common case, but neomake has a direct swiftc example that just parses the current file:

https://github.com/neomake/neomake/blob/76e5b2bad8e98e805ff4749068e6be6206bec2a0/autoload/neomake/makers/ft/swift.vim#L44-L54

from swift.vim.

keith avatar keith commented on June 2, 2024

Kinda related: #142

from swift.vim.

sdondley avatar sdondley commented on June 2, 2024

Thanks. But I'm confused. I don't understand how your module works with Syntastic or how I would integrate neomake with your module or what swiftpm does exactly (I know what a package manager is but I have no idea why it's involved in syntax checking).

So what do I have to do, exactly, to get syntax checking on a standalone file working?

from swift.vim.

sdondley avatar sdondley commented on June 2, 2024

Also, another point of confusion for me is that I've got swift syntax checking working on Ubuntu. But when I run swift pacakage --version on my mac, I get this error:

error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-pacakage (No such file or directory)

So I'm not sure how to get this working on my Mac. I thought the package manager would be installed with xcode, though.

from swift.vim.

keith avatar keith commented on June 2, 2024

You have a typo, it's swift package --version

from swift.vim.

keith avatar keith commented on June 2, 2024

You have a few options:

  1. You can use this plugin and neomake, this plugin will provide highlighting while neomake would provide the syntax checking
  2. If you prefer your current syntax checker you can create a new checker in this repo similar to https://github.com/keith/swift.vim/blob/master/syntax_checkers/swift/swiftpm.vim but replace the fact that it's calling swift build and call swiftc -parse instead.

from swift.vim.

sdondley avatar sdondley commented on June 2, 2024

doh! thanks. I should put my glasses on, I guess. :)

from swift.vim.

keith avatar keith commented on June 2, 2024

Note that SwiftPM isn't actually only doing syntax checking, the way it is setup in this repo it actually does a build of your package, and reports the compiler errors back

from swift.vim.

sdondley avatar sdondley commented on June 2, 2024

OK, I think this is starting to make more sense now. Thank you.

from swift.vim.

sdondley avatar sdondley commented on June 2, 2024

I took a stab at trying to create a new syntax checker (though my vimscript skills are about on par with my swift skills) called swiftc.vim:

if exists('g:loaded_syntastic_swift_swiftc_checker')
  finish
endif
let g:loaded_syntastic_swift_swiftc_checker = 1

if !exists('g:syntastic_swift_swiftc_executable')
  let g:syntastic_swift_swiftc_executable = 'swiftc'
endif

if !exists('g:syntastic_swift_swiftc_arguments')
  let g:syntastic_swift_swiftc_arguments = '-parse'
endif

let s:save_cpo = &cpo
set cpo&vim

function! SyntaxCheckers_swift_swiftc_IsAvailable() dict
  "if !executable(self.getExec())
  "  return 0
  "endif
  return 1

endfunction

function! SyntaxCheckers_swift_swiftc_GetLocList() dict
  let makeprg = self.makeprgBuild({
        \ 'fname': '',
        \ 'args': g:syntastic_swift_swiftc_arguments })

  let errorformat =
        \ '%f:%l:%c: error: %m'

  return SyntasticMake({
        \ 'makeprg': makeprg,
        \ 'errorformat': errorformat })
endfunction

call g:SyntasticRegistry.CreateAndRegisterChecker({
    \ 'filetype': 'swift',
    \ 'name': 'swiftc',
    \ 'exec': g:syntastic_swift_swiftc_executable })

let &cpo = s:save_cpo
unlet s:save_cpo

It doesn't work, though.

from swift.vim.

sdondley avatar sdondley commented on June 2, 2024

OK, I did a little bit more noodling and got something working:

if exists('g:loaded_syntastic_swift_swiftc_checker')
  finish
endif
let g:loaded_syntastic_swift_swiftc_checker = 1

if !exists('g:syntastic_swift_swiftc_executable')
  let g:syntastic_swift_swiftc_executable = 'swiftc'
endif

if !exists('g:syntastic_swift_swiftc_arguments')
  let g:syntastic_swift_swiftc_arguments = ''
endif

let s:save_cpo = &cpo
set cpo&vim

function! SyntaxCheckers_swift_swiftc_IsAvailable() dict
  "if !executable(self.getExec())
  "  return 0
  "endif
  return 1

endfunction

function! SyntaxCheckers_swift_swiftc_GetLocList() dict
    let file = fnameescape(expand("%:p"))
  let makeprg = self.makeprgBuild({
        \ 'fname': file,
        \ 'args': [''] })

  let errorformat = '%f:%l:%c: error: %m,%W%f:%l:%c: warning: %m,%Z%\s%#^~%#,%-G%.%#'

  return SyntasticMake({
        \ 'makeprg': makeprg,
        \ 'errorformat': errorformat })
endfunction

call g:SyntasticRegistry.CreateAndRegisterChecker({
    \ 'filetype': 'swift',
    \ 'name': 'swiftc',
    \ 'exec': g:syntastic_swift_swiftc_executable })

let &cpo = s:save_cpo
unlet s:save_cpo

Are you interested in having me create a patch for this? I'm sure what I have needs to be fixed up and better integrated with your plugin, though.

from swift.vim.

keith avatar keith commented on June 2, 2024

Yep looks good! If you put it in that directory named swiftc.vim it should "just work" if you enable it in your syntastic config

from swift.vim.

Related Issues (20)

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.