Skip to content

Commit 3792761

Browse files
authored
add note about swift file recognition to vim-lsp section (swiftlang#297)
add note about swift file recognition to vim-lsp section
1 parent 21df377 commit 3792761

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Editors/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ All methods below assume `sourcekit-lsp` is in your `PATH`. If it's not then rep
9696

9797
Install [vim-lsp](https://github.com/prabirshrestha/vim-lsp). In your `.vimrc`, configure vim-lsp to use sourcekit-lsp for Swift source files like so:
9898

99-
```
99+
```viml
100100
if executable('sourcekit-lsp')
101101
au User lsp_setup call lsp#register_server({
102102
\ 'name': 'sourcekit-lsp',
@@ -106,14 +106,22 @@ if executable('sourcekit-lsp')
106106
endif
107107
```
108108

109+
In order for vim to recognize Swift files, you need to configure the filetype. Otherwise, `:LspStatus` will show that sourcekit-lsp is not running even if a Swift file is open.
110+
111+
If you are already using a Swift plugin for vim, like [swift.vim](https://github.com/keith/swift.vim), this may be setup already. Otherwise, you can set the filetype manually:
109112

113+
```viml
114+
augroup filetype
115+
au! BufRead,BufNewFile *.swift set ft=swift
116+
augroup END
117+
```
110118

111119
That's it! As a test, open a swift file, put cursor on top of a symbol in normal mode and
112120
run `:LspDefinition`. More commands are documented [here](https://github.com/prabirshrestha/vim-lsp#supported-commands).
113121

114122
There are many Vim solutions for code completion. For instance, you may want to use LSP for omnifunc:
115123

116-
```
124+
```viml
117125
autocmd FileType swift setlocal omnifunc=lsp#complete
118126
```
119127

0 commit comments

Comments
 (0)