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

feat: Install server #247

Merged
merged 22 commits into from
Feb 17, 2024
Merged

Conversation

jcs090218
Copy link
Member

For #120.

copilot.el Show resolved Hide resolved
(defcustom copilot-version "1.14.0"
"Copilot version."
:type 'string
:group 'copilot)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made this variable customizable so the user can choose what version to install.

@emil-vdw
Copy link
Collaborator

As part of this PR, we would also get rid of the dist folder and current chore workflow no?

@zerolfx
Copy link
Collaborator

zerolfx commented Jan 31, 2024

@emil-vdw
We may need two steps:

  1. Prioritize using the agent.js installed by the new method then the old dist folder. If a user is using the agent.js from the dist folder, send a deprecation warning and ask them to install it via the new method.
  2. Remove the dist folder and the chore workflow.

@zerolfx
Copy link
Collaborator

zerolfx commented Jan 31, 2024

@jcs090218
Could you also modify copilot--start-agent to load the agent.js from the new installing method?
It would be better if you check the currently installed version of the NPM package and send a warning if it is mismatched with copilot-version.

@zerolfx
Copy link
Collaborator

zerolfx commented Jan 31, 2024

Prioritize using the agent.js installed by the new method then the old dist folder. If a user is using the agent.js from the dist folder, send a deprecation warning and ask them to install it via the new method.

@emil-vdw After giving it another thought, I realized that this step can be skipped. It's okay to delete dist after providing a new way to install them.

@jcs090218
Copy link
Member Author

We may need two steps:

  1. Prioritize using the agent.js installed by the new method then the old dist folder. If a user is using the agent.js from the dist folder, send a deprecation warning and ask them to install it via the new method.
  2. Remove the dist folder and the chore workflow.

What if we prompt the user to install the server when it's not yet installed in the new location? This is much more straightforward IMO. 🤔 Then we can remove dist and chore workflow in this PR (or later).

Could you also modify copilot--start-agent to load the agent.js from the new installing method?
It would be better if you check the currently installed version of the NPM package and send a warning if it is mismatched with copilot-version.

👍 Done.

@zerolfx
Copy link
Collaborator

zerolfx commented Jan 31, 2024

@jcs090218 Very cool! You solved the long-term issue!

One last request:
Could you test the new installation method on Windows? (In case you have a Windows machine available.)

@jcs090218
Copy link
Member Author

jcs090218 commented Jan 31, 2024

Could you test the new installation method on Windows? (In case you have a Windows machine available.)

Actually, I need someone to test on Unix-like system (linux or macOS), because I'm using Windows now. 😂

I assumed it will work since the code are dragged directly from lsp-mode.

Copy link
Collaborator

@emil-vdw emil-vdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few concerns:

  1. The reliability of the copilot-node-server npm package. Can we trust it to be available, up-to-date and not to be hijacked? Should we investigate whether to pull the agent distributables straight from the corresponding github tag of the official copilot.vim repo?
  2. The fact that at some point a mismatch between the minimum required server version and copilot.el version will break the plugin (see comment below).

copilot.el Outdated Show resolved Hide resolved
copilot.el Outdated Show resolved Hide resolved
copilot.el Outdated Show resolved Hide resolved
jcs090218 and others added 3 commits February 7, 2024 01:04
Co-authored-by: Emil van der Westhuizen <[email protected]>
Co-authored-by: Emil van der Westhuizen <[email protected]>
@jcs090218
Copy link
Member Author

  1. The reliability of the copilot-node-server npm package. Can we trust it to be available, up-to-date and not to be hijacked? Should we investigate whether to pull the agent distributables straight from the corresponding github tag of the official copilot.vim repo?

I don't know much about the upstream copilot.vim, so I cannot suggest this. However, downloading npm packages seems very common in the Emacs world; use lsp-mode and lsp-grammarly as examples.

@emil-vdw
Copy link
Collaborator

emil-vdw commented Feb 7, 2024

I'm not sure but those examples may be using official distributions (albeit through npm). The copilot vim is an official github owned (official copilot) repository so it can be relied upon. The npm package being installed by us through npm is not official and we should at least strongly consider pulling from the official distribution instead.

In my opinion there should be very good reasons for using the unofficial distribution instead.

@jcs090218
Copy link
Member Author

Ah, okay. I thought copilot-node-server is the official... How about publishing our own npm package? Like lsp-grammarly maintains its own grammarly-language-server. 🤔

@zerolfx
Copy link
Collaborator

zerolfx commented Feb 7, 2024

I found the npm package copilot-node-server from https://github.com/TerminalFi/LSP-copilot a long while ago, which is another unofficial Copilot plugin for Sublime. The NPM package is maintained at https://github.com/jfcherng/copilot-node-server.

Maybe we can use it for now and later switch to our own NPM package.

@jcs090218
Copy link
Member Author

jcs090218 commented Feb 7, 2024

Maybe we can use it for now and later switch to our own NPM package.

Yeah, I second this. It would take me some time to do this. Plus, it would make this PR too big if it was implemented in the same PR. 😅

@emil-vdw
Copy link
Collaborator

emil-vdw commented Feb 11, 2024

@jcs090218 I have added some commits to fix some bugs and support Linux. I don't have access to push to your branch though.

jcs-PR#2

@jcs090218
Copy link
Member Author

Merged! :)

@emil-vdw
Copy link
Collaborator

Would you mind testing those changes on Windows again as well?

@jcs090218
Copy link
Member Author

Would you mind testing those changes on Windows again as well?

Yeah, it works now! :)

copilot.el Show resolved Hide resolved
copilot.el Outdated
@@ -245,27 +246,27 @@ Please upgrade the server via `M-x copilot-reinstall-server`"))
"Login to Copilot."
(interactive)
(copilot--dbind
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest are indentation errors.

@jcs090218
Copy link
Member Author

I've made the changes to this PR. Can we merge this? 🤔

Copy link
Collaborator

@emil-vdw emil-vdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to pull main (jsonrpc error handling changes).

Thank you for all of your work on this project! You should have write access now and I will make sure you can merge without review (although try to get a review when practicable).

(cond
((null copilot-node-executable)
(user-error "Could not find node executable"))
((not (file-exists-p copilot-install-dir))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did not catch the condition correctly when I uninstalled the copilot server (this directory is still present). Maybe make it more reliable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you uninstall the server? 🤔 The copilot-install-dir will be gone if you uninstall it through M-x copilot-uninstall-server.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes sense. I did:

npm -g --prefix ~/.emacs.d/.cache/copilot uninstall copilot-node-server

readme.md Outdated Show resolved Hide resolved
readme.md Show resolved Hide resolved
jcs090218 and others added 3 commits February 17, 2024 01:55
Co-authored-by: Emil van der Westhuizen <[email protected]>
Co-authored-by: Emil van der Westhuizen <[email protected]>
@emil-vdw
Copy link
Collaborator

Shall we do the cleanup in a subsequent PR @jcs090218 @zerolfx?

@emil-vdw
Copy link
Collaborator

I think it's fine to clean up in a subsequent PR. Feel free to merge 👍.

@jcs090218 jcs090218 merged commit 26fa165 into copilot-emacs:main Feb 17, 2024
11 checks passed
@sho-87
Copy link

sho-87 commented Feb 18, 2024

this seems to install (or try to start) copilot server at the wrong location:

[stderr] node:internal/modules/cjs/loader:1152
[stderr]   throw err;
[stderr]   ^
[stderr] 
[stderr] Error: Cannot find module 'c:\Users\simon\.emacs.d\.cache\copilot\node_modules\copilot-node-server\copilot\bin\copilot-node-server'
[stderr]     at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
[stderr]     at Module._load (node:internal/modules/cjs/loader:990:27)
[stderr]     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
[stderr]     at node:internal/main/run_main_module:28:49 {
[stderr]   code: 'MODULE_NOT_FOUND',
[stderr]   requireStack: []
[stderr] }
[stderr] 
[stderr] Node.js v21.6.1

the extra copilot beforebin leads to the wrong directory. for ref, the server was installed to C:\Users\simon\.emacs.d\.cache\copilot\node_modules\copilot-node-server\bin\copilot-node-server

@jcs090218
Copy link
Member Author

You are right. It's weird since I did applied the change but it some how got reverted. 🤔

I'm on it.

@jcs090218
Copy link
Member Author

FYI, I've opened the fix in #267. However, I cannot merge PRs without other maintainer's approval. Therefore, the current workaround is to update copilot--server-executable manually.

(setq copilot--server-executable (f-join copilot-install-dir "node_modules" "copilot-node-server" "bin" "copilot-node-server"))

@jmcarcell
Copy link

When opening emacs with this PR I get the following it complains that I should use copilot-install-server but when I try I get
Symbol's value as variable is void: package

@jcs090218
Copy link
Member Author

jcs090218 commented Feb 19, 2024

Can you try toggle-debug-on-error? Paste the backtrack here. Thanks!

Edit: make sure you've updated to the latest version.

@jmcarcell
Copy link

jmcarcell commented Feb 19, 2024

Debugger entered--Lisp error: (void-variable package)
  copilot-install-server()
  funcall-interactively(copilot-install-server)
  call-interactively(copilot-install-server record nil)
  command-execute(copilot-install-server record)
  execute-extended-command(nil "copilot-install-server" "install copilot")
  funcall-interactively(execute-extended-command nil "copilot-install-server" "install copilot")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

Indeed, I get this with main but don't get it if I checkout right before this PR

@jcs090218
Copy link
Member Author

jcs090218 commented Feb 19, 2024

I've made the fix in #268. Thanks for the bug report!

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

Successfully merging this pull request may close these issues.

5 participants