]> granicus.if.org Git - vim/commitdiff
patch 8.2.2085: Qt translation file is recognized as typescript v8.2.2085
authorBram Moolenaar <Bram@vim.org>
Thu, 3 Dec 2020 20:08:37 +0000 (21:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 3 Dec 2020 20:08:37 +0000 (21:08 +0100)
Problem:    Qt translation file is recognized as typescript.
Solution:   Check the first line for "<?xml". (closes #7418)

runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index 6d636ab8fe64d8676c4cc62bbea128c0950bcab3..7dca0e0d32d7a9af08445092f1167e5272619fba 100644 (file)
@@ -1763,8 +1763,13 @@ au BufNewFile,BufReadPost *.tsscl                setf tsscl
 " TWIG files
 au BufNewFile,BufReadPost *.twig               setf twig
 
-" Typescript
-au BufNewFile,BufReadPost *.ts                 setf typescript
+" Typescript or Qt translation file (which is XML)
+au BufNewFile,BufReadPost *.ts
+       \ if getline(1) =~ '<?xml' |
+       \   setf xml |
+       \ else |
+       \   setf typescript |
+       \ endif
 
 " TypeScript with React
 au BufNewFile,BufRead *.tsx                    setf typescriptreact
index 15ba59ae9fbb89331ac51367534113c8bdc43ffd..93540829a554ece72fcf3a053d6040a5ba4a88ea 100644 (file)
@@ -487,7 +487,6 @@ let s:filename_checks = {
     \ 'tssgm': ['file.tssgm'],
     \ 'tssop': ['file.tssop'],
     \ 'twig': ['file.twig'],
-    \ 'typescript': ['file.ts'],
     \ 'typescriptreact': ['file.tsx'],
     \ 'uc': ['file.uc'],
     \ 'udevconf': ['/etc/udev/udev.conf', 'any/etc/udev/udev.conf'],
@@ -709,5 +708,22 @@ func Test_hook_file()
   filetype off
 endfunc
 
+func Test_ts_file()
+  filetype on
+
+  call writefile(['<?xml version="1.0" encoding="utf-8"?>'], 'Xfile.ts')
+  split Xfile.ts
+  call assert_equal('xml', &filetype)
+  bwipe!
+
+  call writefile(['// looks like Typescript'], 'Xfile.ts')
+  split Xfile.ts
+  call assert_equal('typescript', &filetype)
+  bwipe!
+
+  call delete('Xfile.hook')
+  filetype off
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index f3584c1d814b3fa091cbfe68ca65b21090412d69..096698b7f489a5c6d8e1ba6250c811fb3f57fd44 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2085,
 /**/
     2084,
 /**/