Skip to content

Support for language-configuration.json - #9749

Draft
lahodaj wants to merge 21 commits into
apache:masterfrom
lahodaj:language-configuration-support
Draft

lahodaj wants to merge 21 commits into
apache:masterfrom
lahodaj:language-configuration-support

Conversation

@lahodaj

@lahodaj lahodaj commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

VS Code has various configuration files; one of the is language-configuration.json (see https://code.visualstudio.com/api/language-extensions/language-configuration-guide; e.g.: https://github.com/microsoft/vscode/blob/main/extensions/cpp/language-configuration.json). This allows to configure the Toggle comment action, brace matching, some aspects of typing completion, indentation, etc.

The idea in this PR is to start with a support for this configuration. Currently, toggle comment, brace matching and typing completion are (somewhat) supported.

The file can either be specified using API (demonstrated for C/C++), or manually in Tools/Options/Editor/Language Servers.

Note javadoc is partially written by qwen3.8, see: 1f05b50


^Add meaningful description above

Click to collapse/expand PR instructions

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

LLMs, Commit messages and PR description:

  • Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.
  • LLM assisted commits should be attributed with an Assisted-by: MODEL_NAME MODEL_VERSION line appended to the commit message.
    • Please mention coding assistance in the PR description too (eg. by adding the same Assisted-by line from above)
    • Please describe the changes in your own words - we'd like to know you understand the changes being made!

If you're a first time contributor, see the Contributing guidelines for more information.

If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.

PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@lahodaj lahodaj added this to the NB33 milestone Oct 25, 2026
@lahodaj
lahodaj requested review from jtulach and mbien October 25, 2026 11:27
@lahodaj lahodaj added the LSP [ci] enable Language Server Protocol tests label Oct 25, 2026

@jtulach jtulach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • reusing VSCode configuration files is certainly good idea
  • few comments/brainstorming ideas inline

javac.release=17
javac.compilerargs=-Xlint -Xlint:-serial
javadoc.arch=${basedir}/arch.xml
javadoc.apichanges=${basedir}/apichanges.xml

@jtulach jtulach Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am always glad, when a module with an API offers apichanges.xml and they are actually used. It helps to run ant javadoc and read thru the result.

Comment thread nbbuild/build.properties
editor.lib,\
editor,\
lib.uihandler,\
lsp.client,\

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I cannot find lsp.client at https://bits.netbeans.org/dev/javadoc/ right now. I assume this change is going to fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the intent of the change.

*
* <p>Each method is a factory suitable for use as a layer
* {@code instanceCreate} target and should be registered under the
* {@code Editors/<mime-type>}/...} folder or an appropriate sub-folder.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The wording here, gives me some idea, but explicit examples to copy would be more helpful. Maybe I find them near each individual method?

* <p>Requires the {@code mimeType} attribute (String) on the registration
* file. If absent, {@code text/plain} is used as a fallback.
*
* <p>Sample registration:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice example to copy!

</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.jackson</code-name-base>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can already see:

  • ide/c.google.gson
  • libs.json_simple

I assume both the existing libraries could parse the JSON as well. What's your motivation to add Jackson?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, unfortunately, the real-world language configurations (at least the C/C++ one) contain things like comments:
https://github.com/microsoft/vscode/blob/1306698e328e5e531f5e632301d30020aa994eff/extensions/cpp/language-configuration.json#L110

or trailing commas in object definitions:
https://github.com/microsoft/vscode/blob/1306698e328e5e531f5e632301d30020aa994eff/extensions/cpp/language-configuration.json#L106

Given the goal here is to be able to use the unmodified language configuration files, we need a parser that can tolerate both of these, and I believe Gson cannot be configured to tolerate the trailing commas, and the simple json does not tolerate the comments (although I admit I didn't know about the simple json). Jackson can be configured to tolerate both of these misbehaviors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can see the module was already in the enterprise cluster:

nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-annotations-2.17.2.jar         Apache-2.0
nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-core-2.17.2.jar                Apache-2.0
nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-databind-2.17.2.jar            Apache-2.0
nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-dataformat-cbor-2.17.2.jar     Apache-2.0
nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-dataformat-yaml-2.17.2.jar     Apache-2.0
nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-datatype-jsr310-2.17.2.jar     Apache-2.0
nbbuild/netbeans/LICENSE:enterprise/modules/ext/jackson/jackson-module-jaxb-annotations-2.17.2.jar Apache-2.0

moving it to ide causes no harm...

)
})
@GrammarRegistration(grammar="resources/c.tmLanguage.json", mimeType=MIMETypes.C)
@LanguageConfigurationRegistration(languageConfiguration="resources/language-configuration.json", mimeType=MIMETypes.C)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice API.

<fileset>
<file>src/org/netbeans/modules/cpplite/editor/file/resources/language-configuration.json</file>
<license ref="MIT-vscode" />
<comment type="COMMENT_UNSUPPORTED">Source: https://github.com/microsoft/vscode/blob/main/extensions/cpp/language-configuration.json</comment>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • What's the relation between TextMate grammar and this language configuration?
  • Couldn't both these files be consumed by @GrammarRegistration?
  • e.g. add an optional languageConfiguration attribute to @GrammarRegistration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In theory, the language configuration and grammars are independent (after all, they are two independent files). I admit that in practice, it is hard to image a language configuration for a language with a non-Textmate lexer lexer, so, in practice, these are likely to be used together.

I am, however, not convinced that putting "language configuration" into "GrammarRegistration" is appropriate: the language configuration is not really a grammar, and it is certainly not a place where I would look for the registration of the language configuration.

*
* @return language configuration
*/
public String languageConfiguration();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LSP [ci] enable Language Server Protocol tests Need Squashing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants