Skip to content

Commit f78b934

Browse files
authored
Merge pull request #3308 from bhcleek/syntax/import-spell
syntax: ignore misspellings in import paths
2 parents 66ce159 + 5a9df41 commit f78b934

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

autoload/go/highlight_test.vim

+45
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,51 @@ function! s:check_diagnostics(actual, expected, when)
422422

423423
call assert_equal(a:expected, l:actual, a:when)
424424
endfunction
425+
426+
function! Test_goStringHighlight() abort
427+
syntax on
428+
429+
let l:dir = gotest#write_file('highlight/gostring.go', [
430+
\ 'package highlight',
431+
\ '',
432+
\ 'import (',
433+
\ printf("\t%s", '"fmt"'),
434+
\ ')',
435+
\ '',
436+
\ printf('var s = "%s"', "gostring\x1f"),
437+
\ ])
438+
439+
try
440+
let l:pos = getcurpos()
441+
let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name')
442+
call assert_equal('goString', l:actual)
443+
finally
444+
call delete(l:dir, 'rf')
445+
endtry
446+
endfunc
447+
448+
function! Test_goImportStringHighlight() abort
449+
syntax on
450+
451+
let l:dir = gotest#write_file('highlight/import.go', [
452+
\ 'package highlight',
453+
\ '',
454+
\ 'import (',
455+
\ printf('%s"%s"', "\t", "fmt\x1f"),
456+
\ ')',
457+
\ '',
458+
\ 'var s = fmt.Sprint("gostring")',
459+
\ ])
460+
461+
try
462+
let l:pos = getcurpos()
463+
let l:actual = synIDattr(synID(l:pos[1], l:pos[2], 1), 'name')
464+
call assert_equal('goImportString', l:actual, getline('.'))
465+
finally
466+
call delete(l:dir, 'rf')
467+
endtry
468+
endfunc
469+
425470
" restore Vi compatibility settings
426471
let &cpo = s:cpo_save
427472
unlet s:cpo_save

syntax/go.vim

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ else
104104
syn region goRawString start=+`+ end=+`+
105105
endif
106106

107+
syn match goImportString /^\%(\s\+\|import \)\zs"[^"]\+"$/ contained containedin=goImport
108+
107109
if go#config#HighlightFormatStrings()
108110
" [n] notation is valid for specifying explicit argument indexes
109111
" 1. Match a literal % not preceded by a %.
@@ -121,6 +123,7 @@ if go#config#HighlightFormatStrings()
121123
hi def link goFormatSpecifier goSpecialString
122124
endif
123125

126+
hi def link goImportString String
124127
hi def link goString String
125128
hi def link goRawString String
126129

@@ -140,9 +143,9 @@ endif
140143

141144
" import
142145
if go#config#FoldEnable('import')
143-
syn region goImport start='import (' end=')' transparent fold contains=goImport,goString,goComment
146+
syn region goImport start='import (' end=')' transparent fold contains=goImport,goImportString,goComment
144147
else
145-
syn region goImport start='import (' end=')' transparent contains=goImport,goString,goComment
148+
syn region goImport start='import (' end=')' transparent contains=goImport,goImportString,goComment
146149
endif
147150

148151
" var, const

0 commit comments

Comments
 (0)