Repository navigation
Support for language-configuration.json #9749
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
base: master
Are you sure you want to change the base?
Changes from all commits
e18c0b2
413f55f
cbbe31b
5535ea5
5e292cb
1bb6abd
e0e300a
cf1acef
9a0c164
5481e0f
ccca35b
cd20de9
dfe4415
c2b1a47
cfc20b3
f53bbdb
1f05b50
72416ca
5671bbe
b4a172e
32d0dd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import org.netbeans.api.annotations.common.StaticResource; | ||
| import org.netbeans.core.spi.multiview.MultiViewElement; | ||
| import org.netbeans.core.spi.multiview.text.MultiViewEditorElement; | ||
| import org.netbeans.modules.lsp.client.api.LanguageConfigurationRegistration; | ||
| import org.netbeans.modules.textmate.lexer.api.GrammarRegistration; | ||
| import org.openide.awt.ActionID; | ||
| import org.openide.awt.ActionReference; | ||
|
|
@@ -115,6 +116,7 @@ | |
| ) | ||
| }) | ||
| @GrammarRegistration(grammar="resources/c.tmLanguage.json", mimeType=MIMETypes.C) | ||
| @LanguageConfigurationRegistration(languageConfiguration="resources/language-configuration.json", mimeType=MIMETypes.C) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice API. |
||
| public class CDataObject extends MultiDataObject { | ||
|
|
||
| @StaticResource | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| { | ||
| "comments": { | ||
| "lineComment": "//", | ||
| "blockComment": [ | ||
| "/*", | ||
| "*/" | ||
| ] | ||
| }, | ||
| "brackets": [ | ||
| [ | ||
| "{", | ||
| "}" | ||
| ], | ||
| [ | ||
| "[", | ||
| "]" | ||
| ], | ||
| [ | ||
| "(", | ||
| ")" | ||
| ] | ||
| ], | ||
| "autoClosingPairs": [ | ||
| { | ||
| "open": "[", | ||
| "close": "]" | ||
| }, | ||
| { | ||
| "open": "{", | ||
| "close": "}" | ||
| }, | ||
| { | ||
| "open": "(", | ||
| "close": ")" | ||
| }, | ||
| { | ||
| "open": "'", | ||
| "close": "'", | ||
| "notIn": [ | ||
| "string", | ||
| "comment" | ||
| ] | ||
| }, | ||
| { | ||
| "open": "\"", | ||
| "close": "\"", | ||
| "notIn": [ | ||
| "string" | ||
| ] | ||
| }, | ||
| { | ||
| "open": "/*", | ||
| "close": "*/", | ||
| "notIn": [ | ||
| "string", | ||
| "comment" | ||
| ] | ||
| }, | ||
| { | ||
| "open": "/**", | ||
| "close": " */", | ||
| "notIn": [ | ||
| "string" | ||
| ] | ||
| } | ||
| ], | ||
| "surroundingPairs": [ | ||
| [ | ||
| "{", | ||
| "}" | ||
| ], | ||
| [ | ||
| "[", | ||
| "]" | ||
| ], | ||
| [ | ||
| "(", | ||
| ")" | ||
| ], | ||
| [ | ||
| "\"", | ||
| "\"" | ||
| ], | ||
| [ | ||
| "'", | ||
| "'" | ||
| ], | ||
| [ | ||
| "<", | ||
| ">" | ||
| ] | ||
| ], | ||
| "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)", | ||
| "folding": { | ||
| "markers": { | ||
| "start": "^\\s*#\\s*pragma\\s+region\\b", | ||
| "end": "^\\s*#\\s*pragma\\s+endregion\\b" | ||
| } | ||
| }, | ||
| "indentationRules": { | ||
| "decreaseIndentPattern": { | ||
| "pattern": "^\\s*[\\}\\]\\)].*$" | ||
| }, | ||
| "increaseIndentPattern": { | ||
| "pattern": "^.*(\\{[^}]*|\\([^)]*|\\[[^\\]]*)$" | ||
| }, | ||
| }, | ||
| "onEnterRules": [ | ||
| { | ||
| // Decrease indentation after single line if/else if/else, for, or while | ||
| "previousLineText": "^\\s*(((else ?)?if|for|while)\\s*\\(.*\\)\\s*|else\\s*)$", | ||
| // But make sure line doesn't have braces or is not another if statement | ||
| "beforeText": "^\\s+([^{i\\s]|i(?!f\\b))", | ||
| "action": { | ||
| "indent": "outdent" | ||
| } | ||
| }, | ||
| // Add // when pressing enter from inside line comment | ||
| { | ||
| "beforeText": "^\\s*//\\s*\\S|\\s//\\s+\\S", | ||
| "afterText": "^(?!\\s*$)", | ||
| "action": { | ||
| "indent": "none", | ||
| "appendText": "// " | ||
| } | ||
| }, | ||
| ] | ||
| } |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see the module was already in the enterprise cluster: moving it to |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| javac.release=17 | ||
| javac.compilerargs=-Xlint -Xlint:-serial | ||
| javadoc.arch=${basedir}/arch.xml | ||
| javadoc.apichanges=${basedir}/apichanges.xml | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am always glad, when a module with an API offers |
||
| release.external/org.eclipse.lsp4j-0.24.0.jar=modules/ext/org.eclipse.lsp4j-0.24.0.jar | ||
| release.external/org.eclipse.lsp4j.generator-0.24.0.jar=modules/ext/org.eclipse.lsp4j.generator-0.24.0.jar | ||
| release.external/org.eclipse.lsp4j.jsonrpc-0.24.0.jar=modules/ext/org.eclipse.lsp4j.jsonrpc-0.24.0.jar | ||
|
|
@@ -26,4 +27,4 @@ release.external/org.eclipse.lsp4j.jsonrpc.debug-0.24.0.jar=modules/ext/org.ecli | |
| release.external/org.eclipse.xtend.lib-2.32.0.jar=modules/ext/org.eclipse.xtend.lib-2.32.0.jar | ||
| release.external/org.eclipse.xtend.lib.macro-2.32.0.jar=modules/ext/org.eclipse.xtend.lib.macro-2.32.0.jar | ||
| release.external/org.eclipse.xtext.xbase.lib-2.32.0.jar=modules/ext/org.eclipse.xtext.xbase.lib-2.32.0.jar | ||
| spec.version.base=1.37.0 | ||
| spec.version.base=1.38.0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,14 @@ | |
| <specification-version>1.0</specification-version> | ||
| </run-dependency> | ||
| </dependency> | ||
| <dependency> | ||
| <code-name-base>org.netbeans.libs.jackson</code-name-base> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can already see:
I assume both the existing libraries could parse the JSON as well. What's your motivation to add Jackson?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: or trailing commas in object definitions: 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. |
||
| <build-prerequisite/> | ||
| <compile-dependency/> | ||
| <run-dependency> | ||
| <release-version>2</release-version> | ||
| </run-dependency> | ||
| </dependency> | ||
| <dependency> | ||
| <code-name-base>org.netbeans.modules.editor</code-name-base> | ||
| <build-prerequisite/> | ||
|
|
@@ -111,6 +119,15 @@ | |
| <specification-version>1.90</specification-version> | ||
| </run-dependency> | ||
| </dependency> | ||
| <dependency> | ||
| <code-name-base>org.netbeans.modules.editor.bracesmatching</code-name-base> | ||
| <build-prerequisite/> | ||
| <compile-dependency/> | ||
| <run-dependency> | ||
| <release-version>0</release-version> | ||
| <specification-version>1.72</specification-version> | ||
| </run-dependency> | ||
| </dependency> | ||
| <dependency> | ||
| <code-name-base>org.netbeans.modules.editor.breadcrumbs</code-name-base> | ||
| <build-prerequisite/> | ||
|
|
@@ -445,6 +462,10 @@ | |
| <recursive/> | ||
| <compile-dependency/> | ||
| </test-dependency> | ||
| <test-dependency> | ||
| <code-name-base>org.netbeans.modules.lexer.nbbridge</code-name-base> | ||
| <compile-dependency/> | ||
| </test-dependency> | ||
| <test-dependency> | ||
| <code-name-base>org.netbeans.modules.masterfs</code-name-base> | ||
| <compile-dependency/> | ||
|
|
@@ -474,6 +495,7 @@ | |
| </test-type> | ||
| </test-dependencies> | ||
| <public-packages> | ||
| <package>org.netbeans.modules.lsp.client.api</package> | ||
| <package>org.netbeans.modules.lsp.client.debugger.api</package> | ||
| <package>org.netbeans.modules.lsp.client.debugger.spi</package> | ||
| <package>org.netbeans.modules.lsp.client.spi</package> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.netbeans.modules.lsp.client.api; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Repeatable; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /**Register a {@code language-configuration.json} for a given mime type. | ||
| * | ||
| * Will also register language features defined in {@link LanguageFeatures} | ||
| * as appropriate. | ||
| * | ||
| * @since 1.38 | ||
| */ | ||
| @Repeatable(LanguageConfigurationRegistrations.class) | ||
| @Target({ElementType.PACKAGE, ElementType.TYPE}) | ||
| public @interface LanguageConfigurationRegistration { | ||
| /** The mime-type under which the grammar should be registered. | ||
| * | ||
| * @return mime-type | ||
| */ | ||
| public String mimeType(); | ||
|
|
||
| /** The language configuration to register. | ||
| * | ||
| * @return language configuration | ||
| */ | ||
| public String languageConfiguration(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
netbeans/java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/KtDataObject.java
Lines 39 to 48 in e337e53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GrammarRegistration?languageConfigurationattribute to@GrammarRegistration?There was a problem hiding this comment.
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.