Coder Social home page Coder Social logo

done's Introduction

Defold on Neovim (extended)

Note

Work in progress. Tested only on Linux, but it should work on macOS as well.

  • Configures lua_ls to better support defold projects
  • Includes defold API annotations
  • Adds a command to extract dependency annotations
  • Adds commands to build, hot-reload and fetch
  • Configures all defold filetypes to be properly detected and highlighted
  • Works with built-in LSP and with coc.nvim

Intended to be used as external editor.

Dependencies

The plugin can work without dependencies, but if you want to get LSP documentation and completions for external libraries in the ".internal" directory, you need to install these dependencies and invoke DoNe annotate command. To run remote actions, curl and one of ss or lsof utils must be exucutable (most Linux distros and MacOS include them by default).

Make sure luarocks is using 5.1 lua version

luarocks config | grep lua_version

if its not then change it to 5.1

luarocks config lua_version 5.1
sudo luarocks install sha1
sudo luarocks install luazip
sudo luarocks install lyaml

# luazip requires zziplib library
# on ArchLinux zziplib can be installed with
sudo pacman -S zziplib
# On other distros or on macos you can build it from source
# https://github.com/gdraheim/zziplib

Install

Using lazy.nvim and lazy loading only by :Lazy load DoNe command

{
   "monkoose/DoNe",
   lazy = true,
   -- optional configuration
   config = function()
      -- as example adding some keybindings
      vim.keymap.set("n", "<F5>", "<Cmd>DoNe build<CR>")
      --- ...
   end,
}

Usage

DoNe provides neovim user command with the same name :DoNe:

  • :DoNe build - builds and runs defold project
  • :DoNe reload - hot-reloads defold project
  • :DoNe fetch - fetches project dependencies
  • :DoNe annotate - collects dependency annotations for improved autocompletion and documentation. You may need to restart LSP client to get them in the current neovim session.
  • :DoNe clear - removes annotations of all dependencies (useful when you change projects, so autocompletion wouldn't show them)
  • :DoNe actions - lists all available commands accepted by defold editor (it can be used with lua require('done.remote').actions(<cmd-name>))
  • :DoNe delete_server_pipe - if neovim started as an external editor with instructions below and servername=$HOME/.cache/nvim/defold.pipe, then removes the server pipe. Required because from time to time something goes wrong, so neovim stops connectiong to this pipe. Use it when opening an external editor creates new neovim windows.

Script for opening neovim as defold external editor

Name the script how you want (for example, neovim-for-defold), make it executable and put in any directory in your $PATH environment variable. On defold's menu File > Preferences > Code change the Custom Editor field to neovim-for-defold (or the name you chose). Open File at Line should be changed to {file} {line}.

Change st in the script to your favorite terminal in which you would like to start neovim. You don't need to change anything else.

#!/bin/sh

# change this to your favorite terminal
term_exec="st"
servername="$HOME/.cache/nvim/defold.pipe"

if [[ "$#" -eq 2 ]]; then
    command="edit +$2 $1"
else
    command="edit $1"
fi

if [[ -e "$servername" ]]; then
    nvim --server "$servername" --remote-send "<C-\\><C-n>:$command<CR>"
else
    "$term_exec" -e nvim --listen "$servername" +"lua require('lazy').load({ plugins = 'DoNe' })" +"$command"
fi
I'm using slightly modified version for better awesomewm integration.
#!/bin/sh

term_exec="st"
servername="$HOME/.cache/nvim/defold.pipe"

if [[ "$#" -eq 2 ]]; then
    command="edit +$2 $1"
else
    command="edit $1"
fi

if [[ -e "$servername" ]]; then
    nvim --server "$servername" --remote-send "<C-\\><C-n>:$command<CR>"
    awesome-client '
    for _, c in ipairs(client.get()) do
        if string.match(c.name, "=defold=") then
            c:jump_to()
            break
        end
    end
    '
else
    "$term_exec" -e nvim --listen "$servername" +"lua require('lazy').load({ plugins = 'DoNe' })" \
        +"let &titlestring = '=defold=  %t'" +"$command"
fi
Misc notes Defold api annotations were generated with https://github.com/astrochili/defold-annotations TODO: add github workflow to update them automatically

done's People

Contributors

monkoose avatar

Stargazers

Jake Langford avatar Diego Abad avatar  avatar Gustavo Joaquin avatar Roman Silin avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.