Giter Site home page Giter Site logo

[FR]: Lazy_loading luasnippets about scnvim HOT 9 CLOSED

kflak avatar kflak commented on July 19, 2024
[FR]: Lazy_loading luasnippets

from scnvim.

Comments (9)

kflak avatar kflak commented on July 19, 2024 1

Thanks, @davidgranstrom! Didn't think about that approach. It helps a lot, and it also made me take a critical look at what exactly I stuffed into my nvim-cmp sources :-)

from scnvim.

davidgranstrom avatar davidgranstrom commented on July 19, 2024

It has to be up to the snippet framework since scnvim does not load the snippets.

There is an API function to get the path of a generated asset without loading anything, maybe that can be used for lazy loading depending on how the snippet engine works?

local asset_path = require('scnvim.path').get_asset 'snippets'

I have started sketching on a notification system that might be useful for these types of tasks, not sure if it will make it into #153, but I imagine it to work something like this:

--- in init.vim

local notification = require 'scnvim.notification'
notification.add_subscriber('sclang_started', function(object)
  -- executed once sclang has been started
  vim.cmd [[ SCNvimGenerateAssets ]]
end)

from scnvim.

kflak avatar kflak commented on July 19, 2024

Good, good, will start looking into how the other frameworks do the lazy loading and see if this can be used fon sclang.

from scnvim.

davidgranstrom avatar davidgranstrom commented on July 19, 2024

Thinking about this some more, you could probably set up an autocmd for this (e.g. FileType) and load the snippets like you do now but instead the first time entering a supercollider buffer

from scnvim.

kflak avatar kflak commented on July 19, 2024

That works indeed! However, I find nvim very sluggish in general when using the snippets, so I would like to find some other way of loading them. Homework for some other time...

from scnvim.

ranjithshegde avatar ranjithshegde commented on July 19, 2024

because I lazy-load both scnvim and luasnip, to prevent erroring only when one of them is loaded, I use something like this

    vim.api.nvim_create_autocmd("InsertEnter", {
        pattern = "*.scd, *.sc, *.sc_help, *.quark",
        group = some_group_id,
        callback = function()
            require("luasnip").add_snippets("supercollider", require("scnvim/utils").get_snippets())
        end,
        once = true,
    })

Note the once flag!
This does add a lag between 1-2 seconds the very first time I InsertEnter in scnvim but it does the job

Perhaps luasnip has some lazier method that replicates add_snippets method?

from scnvim.

kflak avatar kflak commented on July 19, 2024

Thanks, @ranjithshegde! This works really well now on my system. There may be some small lag when typing, but not too much. I might have to look into how many items nvim-cmp populates the menu with, seems to be connected somehow...

from scnvim.

davidgranstrom avatar davidgranstrom commented on July 19, 2024

Since the auto generated snippet file is quite large I would imagine that limiting the entries for nvim-cmp would help. (I have it configured to only auto complete after typing 3 characters and that seem to work pretty well also for language servers where I've experienced similar lag, not sure how it works with snippets since I'm not using that for the moment)

from scnvim.

kflak avatar kflak commented on July 19, 2024

because I lazy-load both scnvim and luasnip, to prevent erroring only when one of them is loaded, I use something like this

    vim.api.nvim_create_autocmd("InsertEnter", {
        pattern = "*.scd, *.sc, *.sc_help, *.quark",
        group = some_group_id,
        callback = function()
            require("luasnip").add_snippets("supercollider", require("scnvim/utils").get_snippets())
        end,
        once = true,
    })

Note the once flag! This does add a lag between 1-2 seconds the very first time I InsertEnter in scnvim but it does the job

Perhaps luasnip has some lazier method that replicates add_snippets method?

Suddenly this approach stopped working for me, but was easily fixable by replacing

 pattern = "*.scd, *.sc, *.sc_help, *.quark",

with

    pattern = { "*.scd", "*.sc", "*.sc_help", "*.quark"},

from scnvim.

Related Issues (20)

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.