Skip to content
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
80 changes: 80 additions & 0 deletions contrib/nvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Neovim setup for .sloka / .sutra files

Requires Neovim 0.11+ and `uv` on your PATH. Both extensions get the
`nirukta` filetype.

## Install

### With lazy.nvim (recommended)

Add a spec that puts the tree-sitter grammar on the runtimepath and loads
this file:

```lua
local NIRUKTA = vim.fn.expand("~/Software/nirukta")

return {
dir = NIRUKTA .. "/tree-sitter-nirukta",
name = "tree-sitter-nirukta",
lazy = false,
build = "tree-sitter generate"
.. " && cc -shared -fPIC -O2 -I src src/parser.c -o parser/nirukta.so",
config = function()
dofile(NIRUKTA .. "/contrib/nvim/nirukta.lua")
end,
}
```

After changing `grammar.js`, rebuild with `:Lazy build tree-sitter-nirukta`.

### Without a plugin manager

`:source` this file (or copy it into your config); it adds the grammar
directory to the runtimepath itself. Build the parser once as described in
`tree-sitter-nirukta/README.md`.

The server runs out of this repo's virtualenv via `uv run --project`, so
`uv sync` must have been run once.

## What you get

- Syntax highlighting via the tree-sitter grammar in `tree-sitter-nirukta/`
(error-tolerant: highlighting survives while a line is mid-edit).
- Parse errors as diagnostics on every edit (about 200ms after you stop
typing).
- Sandhi, vocabulary, declension, and gloss validation as diagnostics on
open and save, streamed in sloka by sloka. Results are cached per line
(in memory and in `~/.cache/nirukta-lsp/`), so only edited lines are
revalidated and reopening unchanged files is fast; the first-ever pass
over a new verse is the only slow one.
- `K` on a word shows its IAST/Devanagari forms, glosses, declension
analysis, and MW/Apte definitions.
- Completion after `stem->` offers every declined form of the stem with its
case, number, and paradigm (works with nvim-cmp or `<C-x><C-o>`; also for
merged compounds, via the parametric paradigms).
- `vocabulary suggestion` warnings carry quickfixes: `gra` (or
`vim.lsp.buf.code_action()`) inserts the suggested `stem->` prefix while
keeping glosses and accents intact.
- In `.sutra` files, broken `file:` references are flagged; referenced
`.sloka` files are validated when you open them.

## Theming

Highlighting uses standard captures (`@markup.heading`, `@string`,
`@string.special`, `@attribute`, `@operator`, `@punctuation.bracket`,
`@punctuation.delimiter`, `@comment`, `@function`, `@function.method`,
`@string.special.url`). Override them for this language only via the
`.nirukta` suffix, e.g.:

```lua
vim.api.nvim_set_hl(0, "@string.special.nirukta", { fg = "#33B1FF" })
```

## Troubleshooting

- `:checkhealth vim.lsp` shows whether the client attached.
- Set `NIRUKTA_LSP_LOG=/tmp/nirukta-lsp.log` before launching nvim to
capture server logs. Sending `SIGUSR1` to the server process dumps all
thread stacks to `<log>.stacks` if it ever seems stuck.
- No highlighting means `parser/nirukta.so` has not been built yet; see
`tree-sitter-nirukta/README.md`.
35 changes: 35 additions & 0 deletions contrib/nvim/nirukta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Neovim (0.11+) integration for the nirukta language server and
-- tree-sitter grammar. Source this file, or load it from a plugin
-- manager (see README.md).

-- this file lives at <repo>/contrib/nvim/nirukta.lua
local script = debug.getinfo(1, "S").source:sub(2)
local repo = vim.fs.dirname(vim.fs.dirname(vim.fs.dirname(script)))

vim.filetype.add({
extension = {
sloka = "nirukta",
sutra = "nirukta",
},
})

local grammar_dir = repo .. "/tree-sitter-nirukta"
if not vim.tbl_contains(vim.opt.runtimepath:get(), grammar_dir) then
vim.opt.runtimepath:append(grammar_dir)
end

vim.api.nvim_create_autocmd("FileType", {
pattern = "nirukta",
callback = function(ev)
vim.bo[ev.buf].commentstring = "/*%s*/"
pcall(vim.treesitter.start, ev.buf, "nirukta")
end,
})

vim.lsp.config("nirukta", {
cmd = { "uv", "run", "--project", repo, "nirukta-lsp" },
filetypes = { "nirukta" },
root_markers = { "pyproject.toml", ".git" },
})

vim.lsp.enable("nirukta")
2 changes: 1 addition & 1 deletion library/aBinayadarpaRe_1.sloka
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ vAcika[verbal expression]->vAcikam=>vAcikaM sarva[all]+(vANmaya[language]->vANma
AhArya[ornamental expression]->AhAryam=>AhAryaM candra[moon]+tAra[stars]+Adi[etc]=candratArAdi
"Whose ornamental expression is the moon, stars, etc."

tat[that]=>taM nam[praise]->numaH[We] sAttvika[pure]->sAttvikam=>sAttvikaM Siva[lord shiva]->Sivam ..
tat[that]=>tan nam[praise]->numaH[We] sAttvika[pure]->sAttvikam=>sAttvikaM Siva[lord shiva]->Sivam ..
"We praise that pure lord shiva."
4 changes: 2 additions & 2 deletions library/birthday.sloka
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ amfta[nectar]->amftam=>amftaM

--- line ---
sUrya[sun]->sUryaH[the]=>sUryo
jyotis[heavenly bodies]+(gaRa[all]->gaRasya[among])+iva[like]=jyotirgaRasyeva
"like the sun among all the heavenly bodies,"
jyotis[heavenly bodies]+(gaRa[multitude]->gaRasya[among])+iva[like]=jyotirgaRasyeva
"like the sun among the multitude of heavenly bodies,"

taTA[likewise]+eva[indeed]=taTEva tava[your]->te saKitvana[friendship]->saKitvanam ..
"likewise indeed is your friendship."
12 changes: 6 additions & 6 deletions library/mahAmftyuYjayamantra.sloka
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ oM[om]
"om"

--- line ---
tri[three]+ambakam[eyes]=tryambakam=>trya\'mbakaM yajAmahe[We][worship]
tri[three]+(ambaka->ambakam[eyes])=tryambakam=>trya\'mbakaM yajAmahe[We][worship]
"We worship the one with three eyes,"

su[good]+ganDim[fragrance]=suganDim=>su\_ganDiM\'
puzwi[nourisher]+varDanam[growth]=puzwi\_varDa\'nam .
su[good]+(ganDi->ganDim[fragrance])=suganDim=>su\_ganDiM\'
puzwi[nourisher]+(varDana[growth]->varDanam)=puzwi\_varDa\'nam .
"the one of good fragrance, and nourisher of growth"

--- line ---

urvArukam[cucumber]+iva[Like]=u\_rvA\_ru\_kami\'va\_ banDanAt[from][the][stem]=>banDa\'nAn
(urvAruka->urvArukam[cucumber])+iva[Like]=u\_rvA\_ru\_kami\'va\_ banDanAt[from][the][stem]=>banDa\'nAn
"Like a cucumber from the stem,"

mftyoH[from][death]=>mf\_tyor
mftyu[death]->mftyoH[from]=>mf\_tyor
mu\'kzIya\_[May][I][be][liberated]
mA[not]+amftAt[from][immortality]=mAmftA\'t ..
mA[not]+(amfta[immortality]->amftAt[from])=mAmftA\'t ..
"May I be liberated from death, but not from immortality."
Loading