From 8ade8009ee1fb508bf94ca6c8c3cd288f051c55b Mon Sep 17 00:00:00 2001 From: Robin Gagnon Date: Tue, 4 Jan 2022 16:34:55 -0500 Subject: feat(filetype.lua): Add typescript extension to filetype detection (#16923) port from `filetype.vim`; also add `getline` convenience function --- runtime/lua/vim/filetype.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index f7048f3709..bbcbe53eaa 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -19,6 +19,10 @@ local function starsetf(ft) }} end +local function getline(bufnr, lnum) + return api.nvim_buf_get_lines(bufnr, lnum-1, lnum, false)[1] +end + -- Filetypes based on file extension local extension = { -- BEGIN EXTENSION @@ -635,6 +639,13 @@ local extension = { tssop = "tssop", tutor = "tutor", twig = "twig", + ts = function(path, bufnr) + if getline(bufnr, 1):find("<%?xml") then + return "xml" + else + return "typescript" + end + end, tsx = "typescriptreact", uc = "uc", uit = "uil", -- cgit