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: support (Neo)Vim by coc.nvim #439

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Freed-Wu
Copy link

@Freed-Wu Freed-Wu commented Jan 6, 2025

@jnoortheen
Copy link
Collaborator

@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?

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 6, 2025

@jnoortheen
Copy link
Collaborator

coc-nix should be able to use this extension as is.

https://github.com/neoclide/coc.nvim/wiki/Using-coc-extensions#differences-between-coc-extensions-and-vs-code-extensions

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.

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 6, 2025

using the nil/nixd directly as the LSP servers

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.

@jnoortheen
Copy link
Collaborator

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.

@jnoortheen
Copy link
Collaborator

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.

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 6, 2025

you still intent to keep this under this repo, this can be a workspace package with different requirements and packaged/published separately.

There are many same code between VS code client and (Neo)Vim client. a patch can reuse many code.
If you want a seperate packege, just run scripts/patch.sh.

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 6, 2025

is using https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies to define coc package and use it in the code.

Looks intereasting. Hope it will not be too complicated. Can it still work for typescript?

@jnoortheen
Copy link
Collaborator

Sorry to nitpick, but I don't want to patch an already dynamic codebase/language.

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 6, 2025

Can optionalDependencies work for typescript? That means when vscode cannot be imported, import coc.nvim.

@jnoortheen
Copy link
Collaborator

Can optionalDependencies work for typescript? That means when vscode cannot be imported, import coc.nvim.

Yes it would support optional imports.

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 6, 2025

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 coc.nvim, we linter for vim client, otherwise, we linter for vscode client.

@jnoortheen
Copy link
Collaborator

@Freed-Wu you can start from here if you are comfortable with typescript . IMHO, other coc-* extensions I checked , seems to be kept as a separate pacakge in separate repo. It is easier that way.

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 7, 2025

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")
}

@jnoortheen
Copy link
Collaborator

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;

@Freed-Wu
Copy link
Author

Freed-Wu commented Jan 7, 2025

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 {
tsserver 2422: A class can only implement an object type or intersection of object types with statically known members.

Is there any solution to solve it?

@jnoortheen
Copy link
Collaborator

@Freed-Wu I suggest having two workspace-package/module (if the functionality differs in coc & vscode clients) instead of extending the union type.

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.

2 participants