-
-
Notifications
You must be signed in to change notification settings - Fork 27
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: support (Neo)Vim by coc.nvim #439
base: main
Are you sure you want to change the base?
Conversation
@Freed-Wu from my understanding, coc-nix should be able to use this extension as is. If there is any particular incompatibility, it can be handled by settings or through the extension code. Is there any reason choosing to patch the typescript code? |
|
I see, in these cases, I suggest using the nil/nixd directly as the LSP servers. I want to keep the codebase lean as much as possible. |
I tend to provide better user experience by providing an extension, just like VS Code. For example, VS Code also can use nil/nixd directly as the LSP servers. |
Since the package requirements for vscode and coc-nvim is different, I'd take the route of creating a separate package for coc-nvim. If you still intent to keep this under this repo, this can be a workspace package with different requirements and packaged/published separately. |
Another option, to keep this compatible with coc-nvim, is using https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies to define coc package and use it in the code. |
There are many same code between VS code client and (Neo)Vim client. a patch can reuse many code. |
Looks intereasting. Hope it will not be too complicated. Can it still work for typescript? |
Sorry to nitpick, but I don't want to patch an already dynamic codebase/language. |
Can optionalDependencies work for typescript? That means when vscode cannot be imported, import |
Yes it would support optional imports. |
code cannot work: (comes from GPT), anything I did wrong? type ExtensionContext =
| import('coc.nvim').ExtensionContext
| import('vscode').ExtensionContext;
let contextType: ExtensionContext | undefined;
try {
contextType = require('coc.nvim').ExtensionContext;
} catch (e) {
contextType = require('vscode').ExtensionContext;
}
export function activate(context: InstanceType<typeof contextType>) {
console.log('Extension is activated!');
} "devDependencies": {
"@types/node": "^12.12.0",
"@types/vscode": "^1.52.0",
"typescript": "^4.3.5"
},
"optionalDependencies": {
"coc.nvim": "^0.0.80"
} ❯ node_modules/.bin/tsc
src/extension.ts:2:12 - error TS2307: Cannot find module 'coc.nvim' or its corresponding type declarations.
2 | import('coc.nvim').ExtensionContext
~~~~~~~~~~
Found 1 error in src/extension.ts:2 expected: When we add |
Yes, a demo is: import type { ExtensionContext } from 'vscode';
import type { ExtensionContext as ExtensionContext_ } from 'coc.nvim';
let vscode
try {
vscode = require('vscode');
} catch (error) {
vscode = require('coc.nvim');
}
export function activate(context: ExtensionContext | ExtensionContext_) {
vscode.window.showInformationMessage("hello")
} |
Looks tenable, I suggest having aliases like below where feaisble import type { ExtensionContext as VExtensionContext } from 'vscode';
import type { ExtensionContext as CExtensionContext } from 'coc.nvim';
type ExtensionContext = VExtensionContext | CExtensionContext; |
I have done some experiments for some VS code extensions: https://github.com/wader/vscode-jq/pull/8/files And I found some problems: type LanguageClient = LanguageClient_vscode | LanguageClient_coc;
export class Client extends LanguageClient {
Is there any solution to solve it? |
@Freed-Wu I suggest having two workspace-package/module (if the functionality differs in coc & vscode clients) instead of extending the union type. |
https://www.npmjs.com/package/coc-nix
Refer:
https://github.com/valentjn/vscode-ltex/blob/3d0cb8cd9b4d0dc8ef6c08a4f376767820678cf6/src/extension.ts#L8-L14
Difference is vscode-ltex/coc-ltex uses a customized python script
https://github.com/valentjn/vscode-ltex/blob/3d0cb8cd9b4d0dc8ef6c08a4f376767820678cf6/tools/patchForTarget.py
to patch code
we use c language macro preprocessor cpp