mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor!: rename "playground" => "dev" #23919
Problem: "playground" is new jargon that overlaps with existing concepts: "dev" (`:help dev`) and "view" (also "scratch" `:help scratch-buffer`) . Solution: We should consistently use "dev" as the namespace for where "developer tools" live. For purposes of a "throwaway sandbox object", we can use the name "view". - Rename `TSPlayground` => `TSView` - Rename `playground.lua` => `dev.lua`
This commit is contained in:
parent
175e5c8b96
commit
c48b1421af
@ -36,6 +36,8 @@ The following changes may require adaptations in user config or plugins.
|
|||||||
• |LspRequest| autocmd was promoted from a |User| autocmd to a first class
|
• |LspRequest| autocmd was promoted from a |User| autocmd to a first class
|
||||||
citizen.
|
citizen.
|
||||||
|
|
||||||
|
• Renamed `vim.treesitter.playground` to `vim.treesitter.dev`.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
ADDED FEATURES *news-added*
|
ADDED FEATURES *news-added*
|
||||||
|
|
||||||
|
@ -1216,12 +1216,4 @@ LanguageTree:trees({self}) *LanguageTree:trees()*
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {self}
|
• {self}
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
|
||||||
Lua module: vim.treesitter.playground *lua-treesitter-playground*
|
|
||||||
|
|
||||||
inspect_tree({opts}) *vim.treesitter.playground.inspect_tree()*
|
|
||||||
Parameters: ~
|
|
||||||
• {opts} InspectTreeOpts
|
|
||||||
|
|
||||||
vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:
|
vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl:
|
||||||
|
@ -493,7 +493,7 @@ end
|
|||||||
--- argument and should return a string.
|
--- argument and should return a string.
|
||||||
function M.inspect_tree(opts)
|
function M.inspect_tree(opts)
|
||||||
---@cast opts InspectTreeOpts
|
---@cast opts InspectTreeOpts
|
||||||
require('vim.treesitter.playground').inspect_tree(opts)
|
require('vim.treesitter.dev').inspect_tree(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns the fold level for {lnum} in the current buffer. Can be set directly to 'foldexpr':
|
--- Returns the fold level for {lnum} in the current buffer. Can be set directly to 'foldexpr':
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
---@class TSPlaygroundModule
|
---@class TSDevModule
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@class TSPlayground
|
---@class TSTreeView
|
||||||
---@field ns integer API namespace
|
---@field ns integer API namespace
|
||||||
---@field opts table Options table with the following keys:
|
---@field opts table Options table with the following keys:
|
||||||
--- - anon (boolean): If true, display anonymous nodes
|
--- - anon (boolean): If true, display anonymous nodes
|
||||||
--- - lang (boolean): If true, display the language alongside each node
|
--- - lang (boolean): If true, display the language alongside each node
|
||||||
---@field nodes TSP.Node[]
|
---@field nodes TSP.Node[]
|
||||||
---@field named TSP.Node[]
|
---@field named TSP.Node[]
|
||||||
local TSPlayground = {}
|
local TSTreeView = {}
|
||||||
|
|
||||||
---@class TSP.Node
|
---@class TSP.Node
|
||||||
---@field id integer Node id
|
---@field id integer Node id
|
||||||
@ -82,16 +82,16 @@ local function traverse(node, depth, lang, injections, tree)
|
|||||||
return tree
|
return tree
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a new Playground object.
|
--- Create a new treesitter view.
|
||||||
---
|
---
|
||||||
---@param bufnr integer Source buffer number
|
---@param bufnr integer Source buffer number
|
||||||
---@param lang string|nil Language of source buffer
|
---@param lang string|nil Language of source buffer
|
||||||
---
|
---
|
||||||
---@return TSPlayground|nil
|
---@return TSTreeView|nil
|
||||||
---@return string|nil Error message, if any
|
---@return string|nil Error message, if any
|
||||||
---
|
---
|
||||||
---@package
|
---@package
|
||||||
function TSPlayground:new(bufnr, lang)
|
function TSTreeView:new(bufnr, lang)
|
||||||
local ok, parser = pcall(vim.treesitter.get_parser, bufnr or 0, lang)
|
local ok, parser = pcall(vim.treesitter.get_parser, bufnr or 0, lang)
|
||||||
if not ok then
|
if not ok then
|
||||||
return nil, 'No parser available for the given buffer'
|
return nil, 'No parser available for the given buffer'
|
||||||
@ -139,7 +139,7 @@ function TSPlayground:new(bufnr, lang)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local decor_ns = api.nvim_create_namespace('ts.playground')
|
local decor_ns = api.nvim_create_namespace('ts.dev')
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
---@param lnum integer
|
---@param lnum integer
|
||||||
@ -154,11 +154,11 @@ local function get_range_str(lnum, col, end_lnum, end_col)
|
|||||||
return string.format('[%d:%d - %d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
|
return string.format('[%d:%d - %d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Write the contents of this Playground into {bufnr}.
|
--- Write the contents of this View into {bufnr}.
|
||||||
---
|
---
|
||||||
---@param bufnr integer Buffer number to write into.
|
---@param bufnr integer Buffer number to write into.
|
||||||
---@package
|
---@package
|
||||||
function TSPlayground:draw(bufnr)
|
function TSTreeView:draw(bufnr)
|
||||||
vim.bo[bufnr].modifiable = true
|
vim.bo[bufnr].modifiable = true
|
||||||
local lines = {} ---@type string[]
|
local lines = {} ---@type string[]
|
||||||
local lang_hl_marks = {} ---@type table[]
|
local lang_hl_marks = {} ---@type table[]
|
||||||
@ -193,25 +193,25 @@ function TSPlayground:draw(bufnr)
|
|||||||
vim.bo[bufnr].modifiable = false
|
vim.bo[bufnr].modifiable = false
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get node {i} from this Playground object.
|
--- Get node {i} from this View.
|
||||||
---
|
---
|
||||||
--- The node number is dependent on whether or not anonymous nodes are displayed.
|
--- The node number is dependent on whether or not anonymous nodes are displayed.
|
||||||
---
|
---
|
||||||
---@param i integer Node number to get
|
---@param i integer Node number to get
|
||||||
---@return TSP.Node
|
---@return TSP.Node
|
||||||
---@package
|
---@package
|
||||||
function TSPlayground:get(i)
|
function TSTreeView:get(i)
|
||||||
local t = self.opts.anon and self.nodes or self.named
|
local t = self.opts.anon and self.nodes or self.named
|
||||||
return t[i]
|
return t[i]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Iterate over all of the nodes in this Playground object.
|
--- Iterate over all of the nodes in this View.
|
||||||
---
|
---
|
||||||
---@return (fun(): integer, TSP.Node) Iterator over all nodes in this Playground
|
---@return (fun(): integer, TSP.Node) Iterator over all nodes in this View
|
||||||
---@return table
|
---@return table
|
||||||
---@return integer
|
---@return integer
|
||||||
---@package
|
---@package
|
||||||
function TSPlayground:iter()
|
function TSTreeView:iter()
|
||||||
return ipairs(self.opts.anon and self.nodes or self.named)
|
return ipairs(self.opts.anon and self.nodes or self.named)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -228,6 +228,8 @@ end
|
|||||||
--- function, it accepts the buffer number of the source
|
--- function, it accepts the buffer number of the source
|
||||||
--- buffer as its only argument and should return a string.
|
--- buffer as its only argument and should return a string.
|
||||||
|
|
||||||
|
--- @private
|
||||||
|
---
|
||||||
--- @param opts InspectTreeOpts
|
--- @param opts InspectTreeOpts
|
||||||
function M.inspect_tree(opts)
|
function M.inspect_tree(opts)
|
||||||
vim.validate({
|
vim.validate({
|
||||||
@ -238,11 +240,11 @@ function M.inspect_tree(opts)
|
|||||||
|
|
||||||
local buf = api.nvim_get_current_buf()
|
local buf = api.nvim_get_current_buf()
|
||||||
local win = api.nvim_get_current_win()
|
local win = api.nvim_get_current_win()
|
||||||
local pg = assert(TSPlayground:new(buf, opts.lang))
|
local pg = assert(TSTreeView:new(buf, opts.lang))
|
||||||
|
|
||||||
-- Close any existing playground window
|
-- Close any existing dev window
|
||||||
if vim.b[buf].playground then
|
if vim.b[buf].dev then
|
||||||
local w = vim.b[buf].playground
|
local w = vim.b[buf].dev
|
||||||
if api.nvim_win_is_valid(w) then
|
if api.nvim_win_is_valid(w) then
|
||||||
api.nvim_win_close(w, true)
|
api.nvim_win_close(w, true)
|
||||||
end
|
end
|
||||||
@ -261,7 +263,7 @@ function M.inspect_tree(opts)
|
|||||||
b = api.nvim_win_get_buf(w)
|
b = api.nvim_win_get_buf(w)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.b[buf].playground = w
|
vim.b[buf].dev = w
|
||||||
|
|
||||||
vim.wo[w].scrolloff = 5
|
vim.wo[w].scrolloff = 5
|
||||||
vim.wo[w].wrap = false
|
vim.wo[w].wrap = false
|
||||||
@ -330,7 +332,7 @@ function M.inspect_tree(opts)
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local group = api.nvim_create_augroup('treesitter/playground', {})
|
local group = api.nvim_create_augroup('treesitter/dev', {})
|
||||||
|
|
||||||
api.nvim_create_autocmd('CursorMoved', {
|
api.nvim_create_autocmd('CursorMoved', {
|
||||||
group = group,
|
group = group,
|
||||||
@ -399,7 +401,7 @@ function M.inspect_tree(opts)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
pg = assert(TSPlayground:new(buf, opts.lang))
|
pg = assert(TSTreeView:new(buf, opts.lang))
|
||||||
pg:draw(b)
|
pg:draw(b)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
@ -275,7 +275,7 @@ CONFIG = {
|
|||||||
'query.lua',
|
'query.lua',
|
||||||
'highlighter.lua',
|
'highlighter.lua',
|
||||||
'languagetree.lua',
|
'languagetree.lua',
|
||||||
'playground.lua',
|
'dev.lua',
|
||||||
],
|
],
|
||||||
'files': [
|
'files': [
|
||||||
'runtime/lua/vim/treesitter.lua',
|
'runtime/lua/vim/treesitter.lua',
|
||||||
|
Loading…
Reference in New Issue
Block a user