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

not getting any sources on cmp from copilot.lua #24

Closed
marcelarie opened this issue May 15, 2022 · 20 comments
Closed

not getting any sources on cmp from copilot.lua #24

marcelarie opened this issue May 15, 2022 · 20 comments

Comments

@marcelarie
Copy link

marcelarie commented May 15, 2022

I can't get the source on cmp for copilot.lua, I debugged the sources that arrive at the cmp setup and there is no source coming from copilot.lua so the error should come from this plugin (I think…).

copilot.vim works and the user auth works correctly.

I tried to create a minimal config, but I can't get it to work, here is the minimal config:

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match "Windows"

local function join_paths(...)
	local path_sep = on_windows and "\\" or "/"
	local result = table.concat({ ... }, path_sep)
	return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir
if on_windows then
	temp_dir = vim.loop.os_getenv "TEMP"
else
	temp_dir = "/tmp"
end

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local function load_plugins()
	-- only add other plugins if they are necessary to reproduce the issue
	require("packer").startup {
		{
			"wbthomason/packer.nvim",
			{ "neovim/nvim-lspconfig" },
			{ "neovim/nvim-lsp" },
			{ "hrsh7th/nvim-cmp" },
			{ "hrsh7th/cmp-nvim-lsp" },
			{ "github/copilot.vim" }, -- needed for the auth
			{
				"zbirenbaum/copilot.lua",
				event = "VimEnter",
				config = function()
					vim.defer_fn(function()
						require("copilot").setup {}
					end, 100)
				end,
			},
			{
				"zbirenbaum/copilot-cmp",
				after = { "copilot.lua", "nvim-cmp" },
			},
			{ "williamboman/nvim-lsp-installer" },
		},
		config = {
			package_root = package_root,
			compile_path = compile_path,
		},
	}
end

if vim.fn.isdirectory(install_path) == 0 then
	vim.fn.system {
		"git",
		"clone",
		"https://github.com/wbthomason/packer.nvim",
		install_path,
	}
	load_plugins()
	require("packer").sync()
else
	load_plugins()
	require("packer").sync()
end

vim.keymap.set("n", "<Space>w", ":w<cr>")
vim.keymap.set("n", "<Space>q", ":q<cr>")

require "lspconfig"

local cmp = require "cmp"
local kind = cmp.lsp.CompletionItemKind

-- vim.o.completeopt = "menu,menuone,noselect"
vim.opt.completeopt = { "menu", "menuone", "noselect" }

vim.cmd "set shortmess+=c"
vim.cmd "let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy', 'all']"

cmp.setup {
	mapping = {
		["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
		["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
		["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
		["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
		["<C-e>"] = cmp.mapping {
			i = cmp.mapping.abort(),
			c = cmp.mapping.close(),
		},
		["<CR>"] = cmp.mapping.confirm {
			select = true,
			behavior = cmp.ConfirmBehavior.Replace,
		},
	},
	experimental = { ghost_text = true },
	sources = {
		{ name = "copilot" },
		{ name = "nvim_lsp", max_item_count = 5 },
	},
}

require("nvim-lsp-installer").setup {}

In my configuration, cmp works with all the other sources without any problem.

@kozer
Copy link

kozer commented May 16, 2022

Same problem as well. No updates at all. Not sure if the problem lies to my recent update on neovim or something else.
Altghough it seems copilot is attaching properly on the buffer.

@marcelarie
Copy link
Author

Same problem as well. No updates at all. Not sure if the problem lies to my recent update on neovim or something else. Altghough it seems copilot is attaching properly on the buffer.

Screenshot 2022-05-16 at 14 55 58

Same, and I tested copilot.vim and it works.

@marcelarie
Copy link
Author

Might be a copilot-cmp error. I got this on startup:

Screenshot 2022-05-16 at 18 13 02

Error in packer_compiled: ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:142: Vim(source):E484: Can'
t open file /home/marcel/.local/share/nvim/site/pack/packer/opt/copilot-cmp/after/plugin/copilot_cmp.lua
Please check your config for correctness

@zbirenbaum
Copy link
Owner

This is very strange, are both of you on the same platform?

The cmp source comes from copilot-cmp so it would likely be an issue in there, unless one of you has LspInfo not showing copilot

@marcelarie
Copy link
Author

marcelarie commented May 16, 2022

I created an issue there. LspInfo running copilot on my side.

@zbirenbaum
Copy link
Owner

I created an issue there. LspInfo running copilot on my side.

Instinct is telling me this is a breaking change in nvim-cmp so I'll check it out, but I can't figure out why I can't reproduce it if that's the case...

@marcelarie
Copy link
Author

marcelarie commented May 16, 2022

The issue occurs on my work MacBook running macOS (nix package manager) and on my ThinkPad with Linux (NixOS).

@zbirenbaum
Copy link
Owner

The issue occurs on my work MacBook running macOS and on my ThinkPad with Linux.

That's very helpful, thank you!

@rebelot
Copy link

rebelot commented May 16, 2022

I am experiencing the same. macOS, compulsively running on latest nvim/cmp versions. Whatever it is, the change happened in the last 48 hrs

@kozer
Copy link

kozer commented May 17, 2022

I'm on linux. Arch distro more specific

@wizard-28
Copy link

Same issue here. I'm on Pop!_OS

@Hunter-Thompson
Copy link

+1 running arch here.

 Client: copilot (id: 3, pid: 82381, bufnr: [1, 8])
 	filetypes:       
 	autostart:       true
 	root directory:  /home/hunter/smallcase/cdk-eks-cluster-module
 	cmd:             node /home/hunter/.local/share/nvim/site/pack/packer/opt/copilot.lua/copilot/index.js

@zbirenbaum
Copy link
Owner

What I don't get is why I can't seem to trigger this on either of my arch systems. Can anyone with a bit more technical knowledge edit the files in copilot-cmp to get a better idea of exactly where it is that this error occurs?

@johnf
Copy link
Contributor

johnf commented May 18, 2022

@zbirenbaum I straced the copilot process (nothing was coming up in the logs and I can see)

write(1, "{\"jsonrpc\":\"2.0\",\"method\":\"LogMessage\",\"params\":{\"level\":3,\"message\":\"
[ERROR] [fetch] [2022-05-18T00:42:30.479Z] Unhandled status from server:,466,Please upgrade your Copilot extension to continue using this service.\\n\",\"metadataStr\":\"
[ERROR] [fetch] [2022-05-18T00:42:30.479Z]\",\"extra\":[\"Unhandled status from server:\",\"466\",\"Please upgrade your Copilot extension to continue using this service.\\n\"]}}", 402) = 402

I noticed this community/community#16423 so I suspect something has changed on copilot back end and this is related

@zbirenbaum
Copy link
Owner

zbirenbaum commented May 18, 2022

@zbirenbaum I straced the copilot process (nothing was coming up in the logs and I can see)

write(1, "{\"jsonrpc\":\"2.0\",\"method\":\"LogMessage\",\"params\":{\"level\":3,\"message\":\"
[ERROR] [fetch] [2022-05-18T00:42:30.479Z] Unhandled status from server:,466,Please upgrade your Copilot extension to continue using this service.\\n\",\"metadataStr\":\"
[ERROR] [fetch] [2022-05-18T00:42:30.479Z]\",\"extra\":[\"Unhandled status from server:\",\"466\",\"Please upgrade your Copilot extension to continue using this service.\\n\"]}}", 402) = 402

I noticed this github/feedback#16423 so I suspect something has changed on copilot back end and this is related

Thanks, this is just the type of info I was hoping for! I just updated the copilot agent to the latest version, so hopefully that fixes things. If it doesn't I'll go into copilot.vim and see if any new api changes of note were made.

I apologize to everyone here that this is such a big issue and taking a bit to fix, I am graduating on Sunday and was busy trying to get everything in by Monday morning when some of my final submissions were due. I'll try to have this figured out before Friday, but if I can't by then it may have to wait until next week since I have graduation stuff and moveout all weekend, and then a long drive back home to make :(

@johnf
Copy link
Contributor

johnf commented May 18, 2022

@zbirenbaum I'm now seeing

read(0, "Content-Length: 300\r\n\r\n{\"params\":{\"contentChanges\":[{\"rangeLength\":0,\"range\":{\"start\":{\"line\":43,\"character\":9},\"end\":{\"line\":43,\"character\":9}},\"text\":\"n\"}],\"textDocument\":{\"uri\":\"file:\\/\\/\\/home\\/johnf\\/work\\/gladly\\/mobile\\/src\\/screens\\/feed\\/Home.tsx\",\"version\":45}},\"method\":\"textDocument\\/didChange\",\"jsonrpc\":\"2.0\"}", 65536) = 323
read(0, "Content-Length: 6579\r\n\r\n{\"params\":{\"doc\":{\"path\":\"\\/home\\/johnf\\/work\\/gladly\\/mobile\\/src\\/screens\\/feed\\/Home.tsx\",\"position\":{\"line\":43,\"character\":10},\"languageId\":\"typescriptreact\",\"tabsize\":2,\"relativePath\":\"src\\/screens\\/feed\\/Home.tsx\",\"indentsize\":2,\"source\":\"import React, { useEffect, useState } from 'react';\\n\\nimport VersionCheck from 'react-native-version-check';\\nimport { getBundleId } from 'react-native-device-info';\\nimport withObservables from '@nozbe\\/with-observables';\\n\\nimpo"..., 65536) = 6603
epoll_wait(13, [], 1024, 0)             = 0
write(1, "Content-Length: 116\r\n\r\n", 23) = 23
write(1, "{\"jsonrpc\":\"2.0\",\"id\":19,\"error\":{\"code\":-32602,\"message\":\"Invalid params: /doc must have required property 

I then added

uri = 'file://' .. vim.api.nvim_buf_get_name(0),

to get_completion_parameters and that seemed to fix it.

But on that note, congratulations and go and enjoy your graduation, we can all wait till next week 😀

@marcelarie
Copy link
Author

yes no problem take the time you need

@marcelarie
Copy link
Author

@johnf where did you add the uri parameter? :)

johnf added a commit to johnf/copilot.lua that referenced this issue May 19, 2022
@johnf
Copy link
Contributor

johnf commented May 19, 2022

@marcelarie I've created a pull request #25

zbirenbaum pushed a commit that referenced this issue May 19, 2022
@zbirenbaum
Copy link
Owner

zbirenbaum commented May 20, 2022

I think this can be closed thanks to @johnf!

If the issue persists please let me know, but I did some pretty thorough testing and it seems mostly fine.

Couple of quick side notes:

  1. I've noticed longer response times for copilot. This appears to be a (mostly) microsoft issue, but is worsened by some aspects of nvim-cmp's source handling, which isn't meant to be used with high latency completions like the ones provided
  2. Additionally, the long requested feature of adding copilot completions on a newline seemed to be working earlier, but without a starting character the nvim-cmp menu refuses to show. I'm working on a larger patch to both copilot_cmp and nvim-cmp to try and address this (and the first point as well), but I can't promise the nvim-cmp one (which is slightly more impactful) will be merged
  3. I just opened a PR that is fairly likely to get merged at some point given how simple it is, feat: Custom item kinds hrsh7th/nvim-cmp#1003 which will allow me to add a custom kind for copilot, so you can have something like this instead of snippet!
    2022-05-20-021432_866x207_scrot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants