Skip to content

Commit

Permalink
feat(nvim): php support
Browse files Browse the repository at this point in the history
  • Loading branch information
miszo committed Oct 4, 2024
1 parent 903b103 commit 01b6677
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.bo.commentstring = '{{-- %s --}}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.bo.commentstring = '<!-- %s -->'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.bo.commentstring = '<!-- %s -->'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.bo.commentstring = '// %s'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.bo.commentstring = '<!-- %s -->'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;; extends

; AlpineJS attributes
(attribute
(attribute_name) @_attr
(#lua-match? @_attr "^x%-%l")
(#not-any-of? @_attr "x-teleport" "x-ref" "x-transition")
(quoted_attribute_value
(attribute_value) @injection.content)
(#set! injection.language "javascript"))

; Blade escaped JS attributes
; <x-foo ::bar="baz" />
(element
(_
(tag_name) @_tag
(#lua-match? @_tag "^x%-%l")
(attribute
(attribute_name) @_attr
(#lua-match? @_attr "^::%l")
(quoted_attribute_value
(attribute_value) @injection.content)
(#set! injection.language "javascript"))))

; Blade PHP attributes
; <x-foo :bar="$baz" />
(element
(_
(tag_name) @_tag
(#lua-match? @_tag "^x%-%l")
(attribute
(attribute_name) @_attr
(#lua-match? @_attr "^:%l")
(quoted_attribute_value
(attribute_value) @injection.content)
(#set! injection.language "php_only"))))
4 changes: 4 additions & 0 deletions home/dot_config/exact_nvim/exact_lua/exact_config/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
-- vim.cmd([[ set nofoldenable]]) -- Disable folding at startup
vim.opt.foldenable = true

-- LSP Server to use for PHP.
-- Set to "intelephense" to use intelephense instead of phpactor.
vim.g.lazyvim_php_lsp = 'intelephense'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return {
{
'ricardoramirezr/blade-nav.nvim',
ft = { 'blade', 'blade.php' },
},
}
6 changes: 6 additions & 0 deletions home/dot_config/exact_nvim/exact_lua/exact_plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ return {
mason = false,
cmd = { vim.fn.expand('~/.asdf/shims/ruby-lsp') },
},
intelephense = {
enable = true,
},
phpactor = {
enable = false,
},
eslint = {
root_dir = get_root_dir,
},
Expand Down
32 changes: 30 additions & 2 deletions home/dot_config/exact_nvim/exact_lua/exact_plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ return {
{ 'nvim-treesitter/playground', cmd = 'TSPlaygroundToggle' },
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
build = function()
require('nvim-treesitter.install').update({ with_sync = true })()
end,
dependencies = {
'windwp/nvim-ts-autotag',
'RRethy/nvim-treesitter-endwise',
'nvim-treesitter/nvim-treesitter-textobjects',
'nvim-treesitter/nvim-treesitter-context',
'LiadOz/nvim-dap-repl-highlights',
},
opts = function(_, opts)
vim.list_extend(opts.ensure_installed, {
'angular',
'bash',
'blade',
'cpp',
'css',
'dockerfile',
Expand All @@ -22,6 +32,7 @@ return {
'markdown',
'markdown_inline',
'mermaid',
'php',
'prisma',
'regex',
'ruby',
Expand All @@ -39,6 +50,9 @@ return {
'vue',
})
opts.autoinstall = true
opts.highlight = { enable = true }
opts.indent = { enable = true }

-- https://github.com/nvim-treesitter/playground#query-linter
opts.query_linter = {
enable = true,
Expand All @@ -65,15 +79,29 @@ return {
}
end,
config = function(_, opts)
require('nvim-treesitter.configs').setup(opts)
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()

parser_config.blade = {
install_info = {
url = 'https://github.com/EmranMR/tree-sitter-blade',
files = { 'src/parser.c' },
branch = 'main',
},
filetype = 'blade',
}

-- MDX
vim.filetype.add({
extension = {
mdx = 'mdx',
},
pattern = {
['.*%.blade%.php'] = 'blade',
},
})
vim.treesitter.language.register('markdown', 'mdx')

require('nvim-treesitter.configs').setup(opts)
end,
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(directive) @tag
(directive_start) @tag
(directive_end) @tag
(comment) @comment @spell
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
((text) @injection.content
(#not-has-ancestor? @injection.content "envoy")
(#set! injection.combined)
(#set! injection.language php))

((text) @injection.content
(#has-ancestor? @injection.content "envoy")
(#set! injection.combined)
(#set! injection.language bash))


((php_only) @injection.content
(#set! injection.combined)
(#set! injection.language php_only))
((parameter) @injection.content
(#set! injection.language php_only))
8 changes: 4 additions & 4 deletions home/dot_config/exact_nvim/lazyvim.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"extras": [
"lazyvim.plugins.extras.dap.core",
"lazyvim.plugins.extras.test.core",
"lazyvim.plugins.extras.coding.copilot",
"lazyvim.plugins.extras.coding.copilot-chat",
"lazyvim.plugins.extras.coding.mini-comment",
"lazyvim.plugins.extras.coding.mini-surround",
"lazyvim.plugins.extras.coding.neogen",
"lazyvim.plugins.extras.coding.yanky",
"lazyvim.plugins.extras.dap.core",
"lazyvim.plugins.extras.editor.harpoon2",
"lazyvim.plugins.extras.editor.leap",
"lazyvim.plugins.extras.editor.mini-move",
Expand All @@ -20,6 +19,7 @@
"lazyvim.plugins.extras.lang.go",
"lazyvim.plugins.extras.lang.json",
"lazyvim.plugins.extras.lang.markdown",
"lazyvim.plugins.extras.lang.php",
"lazyvim.plugins.extras.lang.ruby",
"lazyvim.plugins.extras.lang.rust",
"lazyvim.plugins.extras.lang.svelte",
Expand All @@ -28,6 +28,7 @@
"lazyvim.plugins.extras.lang.vue",
"lazyvim.plugins.extras.lang.yaml",
"lazyvim.plugins.extras.linting.eslint",
"lazyvim.plugins.extras.test.core",
"lazyvim.plugins.extras.ui.mini-indentscope",
"lazyvim.plugins.extras.ui.treesitter-context",
"lazyvim.plugins.extras.util.dot",
Expand All @@ -41,5 +42,4 @@
"doc/news.txt": "24450"
},
"version": 6
}

}
3 changes: 3 additions & 0 deletions home/dot_tool-versions → home/dot_tool-versions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ golang 1.23.1
lua 5.1
deno 1.46.3
just 1.36.0
{{- if not $isWork }}
php 8.3.12
{{- end }}

0 comments on commit 01b6677

Please sign in to comment.