Calling certain code actions from nvim-jdtls gives error

Describe the bug
Running nvim-jdtls related code actions with lspsaga.vim throws an error.
For example extract_method:
Error executing vim.schedule lua callback: ...are/nvim/plugged/lspsaga.nvim/lua/lspsaga/codeaction.lua:219: attempt to index local 'enriched_ctx' (a nil value)
stack traceback:
        ...are/nvim/plugged/lspsaga.nvim/lua/lspsaga/codeaction.lua:219: in function 'apply_action'
        ...are/nvim/plugged/lspsaga.nvim/lua/lspsaga/codeaction.lua:260: in function 'handler'
        /usr/local/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Calling the same code action from builtin LSP menu works:
:lua vim.lsp.buf.code_action()

Steps to reproduce
I can not provide a simple setup to reproduce as setting up nvim-jdtls is not trivial and requires a Java JRE and also installation of eclipse.jdt.ls.
I may provide a setup on request if really required.
I can also provide further debug output as requested.
Expected behavior
The code action should not throw an error.
Neovim version (nvim -v)
0.8.2
lspsaga commit
e1920eb
Terminal name/version
Gnome Terminal 3.44.0

sry I don't write java.  provide another language project will better.

I only have this problem with some nvim-jdtls code actions. Others work fine.

Only actions 1 and 6 throw an error. Others work fine.
Maybe the LSP debug log helps?
[DEBUG][2023-02-05 11:27:15] .../lua/vim/lsp.lua:1381	"LSP[jdtls]"	"client.request"	1	"textDocument/codeAction"	{  context = {    diagnostics = {}  },  range = {    ["end"] = <1>{      character = 24,      line = 11    },    start = <table 1>  },  textDocument = {    uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"  }}	<function 1>	1
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:285	"rpc.send"	{  id = 28,  jsonrpc = "2.0",  method = "textDocument/codeAction",  params = {    context = {      diagnostics = {}    },    range = {      ["end"] = <1>{        character = 24,        line = 11      },      start = <table 1>    },    textDocument = {      uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"    }  }}
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = "05.02.2023, 11:27:15 >> document/codeAction",    type = 3  }}
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  id = "13",  jsonrpc = "2.0",  method = "workspace/configuration",  params = {    items = { {        scopeUri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java",        section = "java.format.tabSize"      }, {        scopeUri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java",        section = "java.format.insertSpaces"      } }  }}
[INFO][2023-02-05 11:27:15] ...lsp/handlers.lua:489	"05.02.2023, 11:27:15 >> document/codeAction"
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:403	"server_request: callback result"	{  result = { 2, true },  status = true}
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:285	"rpc.send"	{  id = "13",  jsonrpc = "2.0",  result = { 2, true }}
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  id = 28,  jsonrpc = "2.0",  result = { {      command = {        arguments = { "extractMethod", {            context = {              diagnostics = {}            },            range = {              ["end"] = {                character = 24,                line = 11              },              start = {                character = 24,                line = 11              }            },            textDocument = {              uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"            }          } },        command = "java.action.applyRefactoringCommand",        title = "Extract to method"      },      diagnostics = {},      kind = "refactor.extract.function",      title = "Extract to method"    }, {      data = {        pid = "0",        rid = "9"      },      kind = "quickassist",      title = "Add Javadoc for 'main'"    }, {      data = {        pid = "1",        rid = "9"      },      diagnostics = {},      kind = "source.organizeImports",      title = "Organize imports"    }, {      data = {        pid = "2",        rid = "9"      },      diagnostics = {},      kind = "source.generate.constructors",      title = "Generate Constructors"    }, {      data = {        pid = "3",        rid = "9"      },      diagnostics = {},      kind = "source.generate.toString",      title = "Generate toString()"    }, {      command = {        arguments = { {            context = {              diagnostics = {}            },            range = {              ["end"] = {                character = 24,                line = 11              },              start = {                character = 24,                line = 11              }            },            textDocument = {              uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"            }          } },        command = "java.action.overrideMethodsPrompt",        title = "Override/Implement Methods..."      },      diagnostics = {},      kind = "source.overrideMethods",      title = "Override/Implement Methods..."    }, {      data = {        pid = "4",        rid = "9"      },      diagnostics = {},      kind = "source.sortMembers",      title = "Sort Members for 'App.java'"    }, {      data = {        pid = "5",        rid = "9"      },      diagnostics = {},      kind = "source.generate.finalModifiers",      title = "Change modifiers to final where possible"    } }}
[DEBUG][2023-02-05 11:27:15] .../lua/vim/lsp.lua:1381	"LSP[jdtls]"	"client.request"	1	"codeAction/resolve"	{  command = {    arguments = { "extractMethod", {        context = {          diagnostics = {}        },        range = {          ["end"] = {            character = 24,            line = 11          },          start = {            character = 24,            line = 11          }        },        textDocument = {          uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"        }      } },    command = "java.action.applyRefactoringCommand",    title = "Extract to method"  },  diagnostics = {},  kind = "refactor.extract.function",  title = "Extract to method"}	<function 1>	1
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:285	"rpc.send"	{  id = 29,  jsonrpc = "2.0",  method = "codeAction/resolve",  params = {    command = {      arguments = { "extractMethod", {          context = {            diagnostics = {}          },          range = {            ["end"] = {              character = 24,              line = 11            },            start = {              character = 24,              line = 11            }          },          textDocument = {            uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"          }        } },      command = "java.action.applyRefactoringCommand",      title = "Extract to method"    },    diagnostics = {},    kind = "refactor.extract.function",    title = "Extract to method"  }}
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = "05.02.2023, 11:27:15 >> codeAction/resolve",    type = 3  }}
[INFO][2023-02-05 11:27:15] ...lsp/handlers.lua:489	"05.02.2023, 11:27:15 >> codeAction/resolve"
[DEBUG][2023-02-05 11:27:15] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  id = 29,  jsonrpc = "2.0",  result = {    command = {      arguments = { "extractMethod", {          context = {            diagnostics = {}          },          range = {            ["end"] = {              character = 24,              line = 11            },            start = {              character = 24,              line = 11            }          },          textDocument = {            uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"          }        } },      command = "java.action.applyRefactoringCommand",      title = "Extract to method"    },    diagnostics = {},    kind = "refactor.extract.function",    title = "Extract to method"  }}
[DEBUG][2023-02-05 11:27:20] .../lua/vim/lsp.lua:1381	"LSP[jdtls]"	"client.request"	1	"codeAction/resolve"	{  command = {    arguments = { "extractMethod", {        context = {          diagnostics = {}        },        range = {          ["end"] = {            character = 24,            line = 11          },          start = {            character = 24,            line = 11          }        },        textDocument = {          uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"        }      } },    command = "java.action.applyRefactoringCommand",    title = "Extract to method"  },  diagnostics = {},  kind = "refactor.extract.function",  title = "Extract to method"}	<function 1>	21
[DEBUG][2023-02-05 11:27:20] .../vim/lsp/rpc.lua:285	"rpc.send"	{  id = 30,  jsonrpc = "2.0",  method = "codeAction/resolve",  params = {    command = {      arguments = { "extractMethod", {          context = {            diagnostics = {}          },          range = {            ["end"] = {              character = 24,              line = 11            },            start = {              character = 24,              line = 11            }          },          textDocument = {            uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"          }        } },      command = "java.action.applyRefactoringCommand",      title = "Extract to method"    },    diagnostics = {},    kind = "refactor.extract.function",    title = "Extract to method"  }}
[DEBUG][2023-02-05 11:27:20] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = "05.02.2023, 11:27:20 >> codeAction/resolve",    type = 3  }}
[DEBUG][2023-02-05 11:27:20] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  id = 30,  jsonrpc = "2.0",  result = {    command = {      arguments = { "extractMethod", {          context = {            diagnostics = {}          },          range = {            ["end"] = {              character = 24,              line = 11            },            start = {              character = 24,              line = 11            }          },          textDocument = {            uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"          }        } },      command = "java.action.applyRefactoringCommand",      title = "Extract to method"    },    diagnostics = {},    kind = "refactor.extract.function",    title = "Extract to method"  }}
[INFO][2023-02-05 11:27:20] ...lsp/handlers.lua:489	"05.02.2023, 11:27:20 >> codeAction/resolve"

If I look at the error position:
https://github.com/glepnir/lspsaga.nvim/blob/a339339e457bec7f91fdeb8bc3ee3f2313b11c1b/lua/lspsaga/codeaction.lua#L217-L219
It seems that self::enriched_ctx is nil. It should be set in act:send_code_action_request(main_buf, options, cb):
https://github.com/glepnir/lspsaga.nvim/blob/a339339e457bec7f91fdeb8bc3ee3f2313b11c1b/lua/lspsaga/codeaction.lua#L146-L148
I'm trying to figure out, why this method is not called.

if called the send_code_action_request. it not nil i think

The problem only happens if the action is a local function (does that make sense??), i.e. if func is set. Other code actions use a request to workspace/executeCommand and this works.
I added print(vim.inspect(self)) In line 149 in act:send_code_action_request() and in line 216 in act:code_action().
What happens is this:

I open the code actions menu
I see a dump of the object and enrichted_ctx is set

{
  bufnr = 1,
  enriched_ctx = {
    bufnr = 1,
    method = "textDocument/codeAction",
    params = {
      context = {
        diagnostics = {}
      },
      range = {
        ["end"] = <1>{
          character = 27,
          line = 11
        },
        start = <table 1>
      },
      textDocument = {
        uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"
      }
    }
  },
  pending_request = true,
  <metatable> = <2>{
    __index = <table 2>,
    __newindex = <function 1>,
    action_callback = <function 2>,
    action_preview = <function 3>,
    apply_action = <function 4>,
    apply_action_keys = <function 5>,
    clean_context = <function 6>,
    close_action_window = <function 7>,
    code_action = <function 8>,
    do_code_action = <function 9>,
    get_action_diff = <function 10>,
    num_shortcut = <function 11>,
    send_code_action_request = <function 12>,
    set_cursor = <function 13>
  }
}

I select 1
I see another dump of the object but enriched_ctx is not there

{
  <metatable> = <1>{
    __index = <table 1>,
    __newindex = <function 1>,
    action_callback = <function 2>,
    action_preview = <function 3>,
    apply_action = <function 4>,
    apply_action_keys = <function 5>,
    clean_context = <function 6>,
    close_action_window = <function 7>,
    code_action = <function 8>,
    do_code_action = <function 9>,
    get_action_diff = <function 10>,
    num_shortcut = <function 11>,
    send_code_action_request = <function 12>,
    set_cursor = <function 13>
  }
}

Here is my dirty fix. I changed lines 219ff like this:
    if func then
      local enriched_ctx = vim.deepcopy(self.enriched_ctx) or {
        params = command.arguments[2],
      }
      enriched_ctx.client_id = client.id
      print(vim.inspect(enriched_ctx))
      func(command, enriched_ctx)

I don't know, if command.argumens[2] is always set. But it contains the required data. Does this make any sense? Maybe it helps you to find a proper solid fix?
The output of enriched_ctx then looks like this:
{
  client_id = 1,
  params = {
    context = {
      diagnostics = {}
    },
    range = {
      ["end"] = {
        character = 24,
        line = 11
      },
      start = {
        character = 24,
        line = 11
      }
    },
    textDocument = {
      uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"
    }
  }
}

this can fixed but problem not here. if invoke it not be nil unless other space free the codeaction ? the diagnostic will free the code action data. how you called code action from code action command or diagnostic jump window ?

how you called code action from code action command or diagnostic jump window ?

I used the code action command: :Lspsaga code_action.

@glepnir Is there anything I can do to help you debug the problem?
Or would you accept a PR with my (dirty) fix above?

after open codeaction you can do lua print(vim.inspect(require('lspsaga.codeaction'))) to see the current data to check the context stored value . when you got nil then run again. I guess it freed by something.

Fun fact:
:lua print(vim.inspect(require('lspsaga.codeaction')))

equals to
:lua=require('lspsaga.codeaction')

Before code action:

{
  <metatable> = <1>{
    __index = <table 1>,
    __newindex = <function 1>,
    action_callback = <function 2>,
    action_preview = <function 3>,
    apply_action = <function 4>,
    apply_action_keys = <function 5>,
    clean_context = <function 6>,
    close_action_window = <function 7>,
    code_action = <function 8>,
    do_code_action = <function 9>,
    get_action_diff = <function 10>,
    num_shortcut = <function 11>,
    send_code_action_request = <function 12>,
    set_cursor = <function 13>
  }
}

After :Lspsaga code_action

{
  action_bufnr = 12,
  action_tuples = { { 1, {
        data = {
          pid = "0",
          rid = "0"
        },
        diagnostics = {},
        kind = "refactor.inline",
        title = "Inline Method"
      } }, { 1, {
      [...]
  action_winid = 1006,
  bufnr = 1,
  enriched_ctx = {
    bufnr = 1,
    method = "textDocument/codeAction",
    params = {
      context = {
        diagnostics = {}
      },
      range = {
        ["end"] = <1>{
          character = 16,
          line = 13
        },
        start = <table 1>
      },
      textDocument = {
        uri = "file:///home/repos/local/java-demo/app/src/main/java/demo/App.java"
      }
    }
  },
  pending_request = false,
  preview_winid = 1007,
  <metatable> = <2>{
    __index = <table 2>,
    __newindex = <function 1>,
    action_callback = <function 2>,
    action_preview = <function 3>,
    apply_action = <function 4>,
    apply_action_keys = <function 5>,
    clean_context = <function 6>,
    close_action_window = <function 7>,
    code_action = <function 8>,
    do_code_action = <function 9>,
    get_action_diff = <function 10>,
    num_shortcut = <function 11>,
    send_code_action_request = <function 12>,
    set_cursor = <function 13>
  }
}

After executing code action + error

{
  <metatable> = <1>{
    __index = <table 1>,
    __newindex = <function 1>,
    action_callback = <function 2>,
    action_preview = <function 3>,
    apply_action = <function 4>,
    apply_action_keys = <function 5>,
    clean_context = <function 6>,
    close_action_window = <function 7>,
    code_action = <function 8>,
    do_code_action = <function 9>,
    get_action_diff = <function 10>,
    num_shortcut = <function 11>,
    send_code_action_request = <function 12>,
    set_cursor = <function 13>
  }
}

Looks like the codeaction instance is completely reset.

all data freed. but what is the free time is ? when you do codeaction it report it's nil. that's mean it freed before it ? wired. only in java right ?

only in java right ?

Yes, but I did not test much other languages. It only happens if the action is of type func:
https://github.com/glepnir/lspsaga.nvim/blob/a339339e457bec7f91fdeb8bc3ee3f2313b11c1b/lua/lspsaga/codeaction.lua#L217-L219
I think, most code actions are not of this type. But nvim-jdtls has some of them.

make sense  i will try to find some code actions which use func

Could it be related to nvim-jdtls not using lspconfig? Instead it starts the LSP server itself.
https://github.com/mfussenegger/nvim-jdtls#nvim-lspconfig-and-nvim-jdtls-differences
  ┌────────────┐           ┌────────────────┐
  │ nvim-jdtls │           │ nvim-lspconfig │
  └────────────┘           └────────────────┘
       |                         |
      start_or_attach           nvim_lsp.jdtls.setup
       │                              |
       │                             setup java filetype hook
       │    ┌─────────┐                  │
       └───►│ vim.lsp │◄─────────────────┘
            └─────────┘
                .start_client
                .buf_attach_client


Question: How to put a container "on top of a bitmap"

The documentation says for PIXI.particles.Emitter says the following:
// The PIXI.Container to put the emitter in
// if using blend modes, it's important to put this
// on top of a bitmap, and not use the root stage Container
I am using blendmodes, and things look great when the world is black, but when the particles render over brightly colored terrain, it looks awful.  I understand the need to render the particles onto a separate bitmap and then render that bitmap onto the scene, but I'm unsure of how to do this.
Container has a "cacheAsBitmap", but that just takes a snapshot at a single instance in time.
I also tried passing in a RenderTexture to PIXI.particles.Emitter to no avail.  It fails when trying to add children to the RenderTexture.
How do I back a Container by a bitmap?

Ah, by this I meant just rendering your particles over other content - I found that it blended oddly (perhaps only for transparent canvases?) when there was no other content behind the particles. The particle editor background color is actually a tinted 10px texture in a Sprite stretched to fill the area.

I see what you meant by the comment now.  Do you know of a good way of doing an "add" or "screen" blend mode when the background is a bright color?  I want the particles to only blend with each other, not the rest of the scene.

I think the only option there is to have an off stage container for the particles that is rendered to a RenderTexture, and then use a Sprite to display that RenderTexture in your game world.


Stars count doesnt update

When i click on Star icon in QA app, the count changes after i refresh the page. Also there is a problem with star icon. It doesn't show star after refreshing. Can this be fixed in ajax?

I think this can be fixed with Ajax @maharshi-b it would be your best shot to fix it. Remember to keep your code up to date and to push your PR to develop branch.