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

Contribute to json language server with a custom language. #198583

Merged
merged 9 commits into from
Jan 30, 2024

Conversation

RedCMD
Copy link
Contributor

@RedCMD RedCMD commented Nov 18, 2023

Allow extensions to enable the builtin json-language-features extension on their own personal json languageId
PR fixes #198025
@aeschli

following the PR of #146731 as reference

Extensions wanting to enable the json language server
only need to add 3 things to their package.json file:

"main": "",
"extensionDependencies": [
	"vscode.json-language-features"
],
"contributes": {
	"jsonLanguageParticipants": [
		{
			"languageId": "foobar"
		}
	]
}

EDIT: A blank "main": "" is required for "extensionDependencies" to be able to start the json-language-features extension

I am unsure how to go about sending a allowComments setting to the language server
maybe allowComments could be part of schema? EDIT: it already is

const documentSettings: DocumentLanguageSettings = textDocument.languageId === 'jsonc' ? { comments: 'ignore', trailingCommas: 'warning' } : { comments: 'error', trailingCommas: 'error' };
currently I've just hard coded the snippets language in jsonServer.ts#L363 EDIT: removed
and everything relating to comments in languageParticipants.ts#L17-L21 is currently unused

@RedCMD
Copy link
Contributor Author

RedCMD commented Dec 4, 2023

@aeschli should I remove the optional allow comments sections?
as I'm not sure how to hook them up with the language server

@aeschli
Copy link
Contributor

aeschli commented Dec 4, 2023

It would be nice if we can keep it simple an only support extending json, not also jsonc.

That said, yes, it's already possible to allow comments via scheme, but again, we consider this a VS Code internal thing.

@aeschli
Copy link
Contributor

aeschli commented Dec 4, 2023

I don't want to hard code the snippets language...

We need to give the server a list of language ids. It e.g. needs it to dynamically register the formatters. I think that's an oversight in the HTML code.
Along with that list we can also give the 'allowComment`.

@RedCMD
Copy link
Contributor Author

RedCMD commented Dec 4, 2023

It e.g. needs it to dynamically register the formatters.

Found it

const documentSelector = [{ language: 'json' }, { language: 'jsonc' }];

Yeah.. html does hardcode handlebars for its dynamic formatter

const documentSelector = [{ language: 'html' }, { language: 'handlebars' }];

Tho I still have no idea how to pass the languageParticipants to the server
would you be able to give me a pointer in the right direction?

only support extending json, not also jsonc
we can also give the allowComment

I'm not sure I understand, you don't want to support extending jsonc, but you do want to support allowComment?
Currently I have no difference between json and jsonc other than allowComment

it's already possible to allow comments via scheme
I don't want to hard code the snippets language...

I've double checked that works, so I guess I can safely remove the hardcoded snippets from jsonServer.ts#L363
global-snippets.json#L3
image

@RedCMD RedCMD requested a review from aeschli January 20, 2024 20:04
@aeschli
Copy link
Contributor

aeschli commented Jan 29, 2024

Thanks, now all looks good. I'll merge it for February.

@aeschli aeschli enabled auto-merge (squash) January 30, 2024 11:00
@vscodenpa vscodenpa added this to the February 2024 milestone Jan 30, 2024
@aeschli aeschli merged commit eee4b5f into microsoft:main Jan 30, 2024
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants