Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(In-progress) Streamline creation of development environment and add usage documentation. #5

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Bug Report
description: File a bug report
title: "[Bug]"
labels: bug
body:
- type: textarea
id: issue
attributes:
label: Description of the issue
description: What's the issue you encountered?
validations:
required: true
- type: textarea
id: repro
attributes:
label: Reproduction steps
description: How can the issue be reproduced?
placeholder: Describe each step as precisely as possible
validations:
required: true
# TODO: Figure out banana logger :|
#
# - type: textarea
# id: log
# attributes:
# label: Log file
# description: loggy loggy
# validations:
# required: true
- type: input
id: version
attributes:
label: Neovim Version
description: In your terminal, run `nvim --version`
placeholder: "e.g. 0.10.1"
validations:
required: true
- type: textarea
id: config
attributes:
label: Minimal Snippet
description: For ease of replication in the case of complex behaviour, paste a small snippet with which the bug occurs.
validations:
required: true
- type: textarea
id: additional-context
attributes:
label: Additional context?
description: |
- Additional info about your environment:
- Any other information relevant to your issue.
validations:
required: false
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Feature Request
description: Suggest a new feature.
title: "[Feature Request]"
body:
- type: textarea
id: overview
attributes:
label: Overview
description: Include the basic, high-level concepts for this feature here. If this is an API request, please provide a link to the browser documentation.
validations:
required: true
- type: textarea
id: details
attributes:
label: Smaller details
description: These may include specific methods of implementation etc. Take a look at `TODO.md` in order to see if your request is related to any other planned features.
validations:
required: true
- type: textarea
id: feature
attributes:
label: Why would this feature be useful?
description: This could include a specific project scenario, or a common inefficiency you have noticed.
validations:
required: true
74 changes: 74 additions & 0 deletions USAGE.md
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this seems really great, thank you so much for doing this!

However, there are a few things that you have setup that I disagree with:

  • the remapping in the jumpstart.lua file should be done in the plugin's setup method
  • the instance could probably be lazily loaded to not trigger unnecessary parsing (this can be done with an if instance == nil ... in the keymap)
  • when you say "all of your lua scripts are called from the index.nml file", i think it might need to be clarified that the banana specific lua scripts are called from the index.nml file. plugin authors will still need their own lua scripts with setup methods, apis and the like. my vision with banana is that a good plugin has a really good api that the plugin author uses for the banana pages (i essentially want banana to incentivize having a good api)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thing: maybe have a top and left property on the nml selector just to show that the user can change the position with those properties

The rest of this all looks really great and I'm really looking forward to when I can merge this into main

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll specify that the jumpstart file should not be part of the actual plugin, it's just a way to open the page itself for simpler projects. That's why I had it outside the normal project file structure. I haven't had as much time as I would like to work on the docs due to being out of the country, but now I can incorporate your feedback!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, thanks for clarifying, I was a bit confused by that

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Usage

Below is a minimal config for using banana during development:

```lua
return {
dir = "~/path/to/project/directory",
build = function()
require("banana").installTsParsers()
end,
config = function()
require("banana").initTsParsers()
end,
}
```

Because banana uses custom parsers for nml and ncss, they must be registered and compiled manually by treesitter. With this config, you are able to get fancy-schmancy syntax highlighting for ncss and nml.

## Project Setup

Banana's hello world uses the below directory structure:

```
PWD
├── jumpstart.lua
├── banana
│   └── random_name
│   └── index.nml
└── lua
└── example
└── init.lua
```

The `jumpstart.lua` file will contain the following code, which will not change:

```lua
-- jumpstart.lua

local instance = require("banana").newInstance("stuff/clock", "random buffer name")

vim.keymap.set("n", "<leader>o", function()
instance:open()
end, {})
```

By sourcing this file using the `:so` command, you are able to toggle opening and closing the banana page instance. This file is used for launching pages directly. If you want to launch your page later, as part of your plugin logic, then all you need to do is place these lines in whatever configuration that your plugin needs.

Notice that the banana nml package and the lua package don't have the same name. Banana does not require any sort of name coupling between the names of packages requiring each other; you can expect banana's require to have similar behaviour to that of lua's require. (Remember that banana uses "/" instead of ".")

## Project Content

Alright, enough preamble, it's time to get to the fun part. One thing that's important to remember when developing a banana plugin is that the nml is your entry point into your banana page; all of your lua scripts are called from that nml page. With that in mind, let's take a look at the following nml file:

```html
<nml>
<head>
<style>
nml {
width: 50%;
height: 50%;
}
div {
hl-bg: red;
width: 50%;
}
</style>
</head>
<body>
<div>Hello World!</div>
</body>
</nml>
```

Awfully underwhelming, huh?
82 changes: 54 additions & 28 deletions lua/banana/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local M = {}
local counterInst = nil
local todoInst = nil
local instance = nil
Expand All @@ -7,9 +6,58 @@ local inst = nil
local render = require("banana.lazyRequire")("banana.instance")
local ffi = require("ffi")

---@class Banana
---@field newInstance function
---@field emptyInstance function
---@field getInstance function
---@field getNilAst function
---@field listInstanceIds function
---@field examples table
local M = {
newInstance = render.newInstance,
emptyInstance = render.emptyInstance,
getInstance = render.getInstance,
getNilAst = render.getNilAst,
listInstanceIds = render.listInstanceIds,
}


local tsInit = false
local tsInstall = false

---@class Banana.Examples
---@field runCounter function
---@field runTodo function
---@field runLazy function
M.examples = {
runCounter = function ()
if counterInst == nil then
counterInst = M.newInstance("examples/counter", "asdf")
-- instance.DEBUG = true
end
counterInst:open()
end,

runTodo = function ()
if todoInst == nil then
todoInst = M.newInstance("examples/todo", "asdf")
-- instance.DEBUG = true
end
todoInst:open()
end,

runLazy = function ()
if instance == nil then
instance = M.newInstance("examples/lazy", "")
-- instance.DEBUG = true
-- instance.DEBUG_showPerf = true
-- instance.DEBUG_stressTest = true
end
instance:open()
instance:_requestRender()
end,
}

M.test = {
grid = function ()
-- print(jit.status())
Expand All @@ -36,32 +84,6 @@ M.test = {
end
}

M.runCounter = function ()
if counterInst == nil then
counterInst = render.newInstance("examples/counter", "asdf")
-- instance.DEBUG = true
end
counterInst:open()
end
M.runTodo = function ()
if todoInst == nil then
todoInst = render.newInstance("examples/todo", "asdf")
-- instance.DEBUG = true
end
todoInst:open()
end

M.runLazy = function ()
if instance == nil then
instance = render.newInstance("examples/lazy", "")
-- instance.DEBUG = true
-- instance.DEBUG_showPerf = true
-- instance.DEBUG_stressTest = true
end
instance:open()
instance:_requestRender()
end

function M.spam()
local testFile = [[
.asdf {
Expand Down Expand Up @@ -110,6 +132,8 @@ function M.initTsParsers()
end
tsInit = true
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()

vim.filetype.add({ extension = { nml = "nml" } })
vim.treesitter.language.register("nml", "nml")
---@diagnostic disable-next-line: inject-field
parser_config.nml = {
Expand All @@ -122,6 +146,9 @@ function M.initTsParsers()
},
filetype = "nml",
}

vim.filetype.add({ extension = { ncss = "ncss" } })
vim.treesitter.language.register("ncss", "ncss")
---@diagnostic disable-next-line: inject-field
parser_config.ncss = {
install_info = {
Expand All @@ -133,7 +160,6 @@ function M.initTsParsers()
},
filetype = "ncss",
}
vim.treesitter.language.register("ncss", "ncss")
end

return M
Loading