Skip to content

Commit 25593e8

Browse files
authored
Merge pull request #238 from esmasth/esmasth/issue233
Refine and distribute yang-lsp-settings-schema.json
2 parents 0e0d1c6 + 7814a29 commit 25593e8

File tree

11 files changed

+194
-141
lines changed

11 files changed

+194
-141
lines changed

Diff for: .editorconfig

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
root = true
22

3-
[*.json]
3+
[*]
44
charset = utf-8
55
trim_trailing_whitespace = true
66
end_of_line = lf
77
insert_final_newline = true
8+
9+
[{*.json,yang.settings}]
810
indent_style = space
911
indent_size = 2
1012

1113
[*.md]
12-
charset = utf-8
13-
trim_trailing_whitespace = true
14-
end_of_line = lf
15-
insert_final_newline = true
14+
indent_style = space
15+
indent_size = 2
16+
17+
[*.gradle]
18+
indent_style = tab
19+
indent_size = 4
20+
21+
[gradlew]
22+
indent_style = space
23+
indent_size = 4
24+
25+
[gradlew.bat]
26+
end_of_line = crlf
27+
28+
[*.yml]
1629
indent_style = space
1730
indent_size = 2

Diff for: .vscode/tasks.json

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"kind": "build",
1313
"isDefault": true
1414
}
15+
},
16+
{
17+
"label": "Gradle Build Distribution",
18+
"type": "shell",
19+
"command": "cd yang-lsp && ./gradlew --no-daemon build copyDist",
20+
"problemMatcher": [],
21+
"group": {
22+
"kind": "build",
23+
"isDefault": false
24+
}
1525
}
1626
]
1727
}

Diff for: README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# yang-lsp
22

3-
[![GH Build Status](https://github.com/theia-ide/yang-lsp/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/theia-ide/yang-lsp/actions/workflows/main.yml)
3+
[![GH Build Status](https://github.com/TypeFox/yang-lsp/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/TypeFox/yang-lsp/actions/workflows/main.yml)
44
[![Build status](https://ci.appveyor.com/api/projects/status/96eo9k5yo0wtpj50/branch/master?svg=true)](https://ci.appveyor.com/project/kittaakos/yang-lsp/branch/master)
55

66
A language server for YANG (see [Language Server Protocol](https://github.com/Microsoft/language-server-protocol)).
@@ -17,13 +17,13 @@ Both variants include start scripts to launch the background process. Connect it
1717
The YANG Language Server is currently being used in
1818

1919
- [YANGSTER](https://github.com/theia-ide/yangster) based on [Theia](https://github.com/theia-ide/theia) (incl. diagram extension)
20-
- [Yang VS Code](https://github.com/theia-ide/yang-vscode) available on the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=typefox.yang-vscode)
20+
- [Yang VS Code](https://github.com/TypeFox/yang-vscode) available on the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=typefox.yang-vscode)
2121
- [Yang Eclipse](https://github.com/theia-ide/yang-eclipse)
2222

2323
## Build
2424

2525
```shell
26-
git clone https://github.com/theia-ide/yang-lsp.git
26+
git clone https://github.com/TypeFox/yang-lsp.git
2727
cd yang-lsp/yang-lsp
2828
./gradlew build
2929
```
@@ -33,10 +33,10 @@ The YANG Language Server is currently being used in
3333
The yang-lsp is the base of multiple binaries
3434

3535
| Repository | Client | Binary | Bin Repo | CI | Trigger |
36-
| ---------- | ------ | ------ | -------- | --- | ---------- |
37-
| [yang-lsp](https://github.com/theia-ide/yangs-lsp) | LSP | JAR + script | GH Action Artifacts | [GH Action](https://github.com/theia-ide/yang-lsp/actions/workflows/main.yml) | GH Commit / PR |
36+
| ---------- | ------ | ------ | -------- | --- | ------- |
37+
| [yang-lsp](https://github.com/TypeFox/yangs-lsp) | LSP | JAR + script | GH Action Artifacts | [GH Action](https://github.com/TypeFox/yang-lsp/actions/workflows/main.yml) | GH Commit / PR |
3838
| [yangster](https://github.com/theia-ide/yangster) | Theia Browser | Docker image | Docker Hub | [Docker Hub](https://hub.docker.com/r/typefox/yangster/builds) | GitHub hook / Jenkins pipeline|
3939
| | Theia | Theia extension| npm | [Jenkins](http://services.typefox.io/open-source/jenkins/job/yangster/) | `yarn run publish` |
4040
| [yangster-electron](https://github.com/theia-ide/yangster-electron) | Theia Electron | executables | ? | ? | ? |
4141
| [yang-eclipse](https://github.com/theia-ide/yang-eclipse) | Eclipse | p2 update site | Eclipse Marketplace | [Jenkins](http://services.typefox.io/open-source/jenkins/job/yang-eclipse/) | GitHub hook / Jenkins pipeline |
42-
| [yang-vscode](https://github.com/theia-ide/yang-vscode) | VSCode | VSCode extension | VSCode Marketplace | - | `vsce` |
42+
| [yang-vscode](https://github.com/TypeFox/yang-vscode) | VSCode | VSCode extension | VSCode Marketplace | - | `vsce` |

Diff for: appveyor.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ build_script:
1111
- ./yang-lsp/gradlew.bat -p yang-lsp build --refresh-dependencies --no-daemon
1212

1313
cache:
14-
- C:\Users\appveyor\.gradle
15-
- C:\Users\appveyor\.m2
14+
- C:\Users\appveyor\.gradle
15+
- C:\Users\appveyor\.m2

Diff for: docs/Extensions.md

+57-51
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Extensions
22

3-
The yang-lsp allows to have additional third party extensions, configured through the [`yang.settings` file](Settings.md).
4-
That file must be located in the root of an opened directory must conform to JSON syntax.
3+
The yang-lsp allows to have additional third party extensions, configured through `yang.settings`.
4+
For details on file format and schema see [Settings.md](./Settings.md).
55

66
So far two different kinds of extensions are supported :
7-
- Validators (`IValidatorExtension`)
8-
- Commands (`ICommandExtension`)
7+
8+
- Validators (`IValidatorExtension`)
9+
- Commands (`ICommandExtension`)
910

1011
## Create a Validator
1112

12-
A validator extension is a Java class that implements the interface `io.typefox.yang.validation.IValidatorExtension`.
13+
A validator extension is a Java class that implements the interface `io.typefox.yang.validation.IValidatorExtension`.
1314
Here is a small example:
1415

1516
```java
@@ -19,72 +20,77 @@ package my.pack;
1920

2021
public class MyExampleValidator implements IValidatorExtension {
2122

22-
public static final String BAD_NAME = "bad_name";
23+
public static final String BAD_NAME = "bad_name";
2324

24-
@Override
25-
public void validate(AbstractModule module, IAcceptor<Issue> issueAcceptor, CancelIndicator cancelIndicator) {
26-
if (module.getName().equals("foo")) {
27-
issueAcceptor.accept(IssueFactory.createIssue(module, YangPackage.Literals.ABSTRACT_MODULE__NAME, "'foo' is a bad name", BAD_NAME));
28-
}
29-
}
25+
@Override
26+
public void validate(AbstractModule module, IAcceptor<Issue> issueAcceptor, CancelIndicator cancelIndicator) {
27+
if (module.getName().equals("foo")) {
28+
issue = IssueFactory.createIssue(module, YangPackage.Literals.ABSTRACT_MODULE__NAME,
29+
"'foo' is a bad name", BAD_NAME)
30+
issueAcceptor.accept();
31+
}
32+
}
3033

3134
}
32-
```
35+
```
3336

3437
## Create a Command Extension
3538

36-
A command extension contributes actions, that will be shown in the context menu of a supporting client (currently only Yangster supports it).
39+
A command extension contributes actions, that will be shown in the context menu
40+
of a supporting client (currently only Yangster supports it).
41+
3742
Here is an example:
3843

39-
```xtend
44+
```java
4045
class MyCommand implements ICommandExtension {
4146

42-
static val COMMAND = "Create a file name 'foo.txt'."
43-
44-
/**
45-
* return a list of commands. A command string is used as ID internally and as a label in the UI.
46-
*/
47-
override getCommands() {
48-
#[COMMAND]
49-
}
50-
51-
/**
52-
* Called when the user asked to execute a certain command.
53-
*/
54-
override executeCommand(String command, Resource resource, LanguageClient client) {
55-
if (COMMAND == command) {
56-
// get the project directory
57-
val uri = ProjectConfigAdapter.findInEmfObject(resource.resourceSet)?.projectConfig?.path.toFileString
58-
val f = new File(uri, 'foo.txt')
59-
if (f.exists) {
60-
client.showMessage(new MessageParams => [
61-
message = 'Such a file already exists.'
62-
])
63-
} else {
64-
f.createNewFile
65-
}
66-
}
67-
}
68-
47+
static val COMMAND = "Create a file name 'foo.txt'."
48+
49+
/**
50+
* return a list of commands. A command string is used as ID internally and as a label in the UI.
51+
*/
52+
override getCommands() {
53+
#[COMMAND]
54+
}
55+
56+
/**
57+
* Called when the user asked to execute a certain command.
58+
*/
59+
override executeCommand(String command, Resource resource, LanguageClient client) {
60+
if (COMMAND == command) {
61+
// get the project directory
62+
val uri = ProjectConfigAdapter.findInEmfObject(resource.resourceSet)?.projectConfig?.path.toFileString
63+
val f = new File(uri, 'foo.txt')
64+
if (f.exists) {
65+
client.showMessage(new MessageParams => [
66+
message = 'Such a file already exists.'
67+
])
68+
} else {
69+
f.createNewFile
70+
}
71+
}
72+
}
73+
6974
}
7075
```
7176

72-
7377
## Package an extension
7478

75-
The class needs to be packaged in a jar. So simply use the java build tool of your preference to create a jar from it. Put the jar somewhere relative to the project's root directory.
79+
The class needs to be packaged in a jar. So simply use the java build tool of
80+
your preference to create a jar from it. Put the jar somewhere relative to the
81+
project's root directory.
7682

7783
## Add the plugin
7884

79-
Create (or open) the `yang.settings` file and add the plugin using the following configuration:
85+
Create (or open) the `yang.settings` file and add the plugin using the following
86+
configuration:
8087

8188
```json
82-
"extension" : {
83-
"classpath" : "extension.jar",
84-
"validators" : "my.pack.MyExampleValidator",
85-
"commands" : "my.pack.MyCommand"
86-
}
89+
"extension" : {
90+
"classpath" : "extension.jar",
91+
"validators" : "my.pack.MyExampleValidator",
92+
"commands" : "my.pack.MyCommand"
93+
}
8794
```
8895

8996
The language server will automatically pick up the extension.
90-

Diff for: docs/Processing_Files.md

+53-52
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Processing YANG files
1+
# Processing YANG files
22

33
As yang-lsp contains all the tools to parse, link and validate YANG models. If you want to further process the YANG files you authored with yang-lsp it makes sense to make reuse of the existing functionality.
44

55
Here is some example code in Xtend for an application that reads in all YANG files from a given directory. The files are parsed into our YANG EMF model, all cross-references are resolved and all files are validated. If there are no errors, the method `generate()` is called for all resources:
66

7-
```Xtend
7+
```xtend
88
package io.typefox.yang.example
99
1010
import com.google.inject.Inject
@@ -20,66 +20,67 @@ import org.eclipse.xtext.util.CancelIndicator
2020
import org.eclipse.xtext.validation.CheckMode
2121
import org.eclipse.xtext.validation.IResourceValidator
2222
23-
class StandaloneExample {
24-
25-
def static void main(String... args) {
26-
val injector = new YangStandaloneSetup().createInjectorAndDoEMFRegistration
27-
injector.getInstance(StandaloneExample).run(args)
28-
}
29-
30-
@Inject XtextResourceSet resourceSet
31-
@Inject IResourceValidator validator
32-
boolean hasErrors = false
33-
34-
def void run(String... args) {
35-
addFile(new File(args.head))
36-
resourceSet.resources.forEach [ resource |
37-
EcoreUtil.resolveAll(resource)
38-
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
39-
issues.forEach [ issue |
40-
hasErrors = hasErrors || issue.severity === Severity.ERROR
41-
System.err.println(issue)
42-
]
43-
]
44-
if(!hasErrors) {
45-
resourceSet.resources.forEach [
46-
generate
47-
]
48-
}
49-
}
50-
51-
def void addFile(File file) {
52-
if(file.isDirectory)
53-
file.listFiles.forEach[ addFile ]
54-
else if(file.name.endsWith('.yang'))
55-
resourceSet.getResource(URI.createURI(file.toURI.toString), true)
56-
}
57-
58-
def generate(Resource resource) {
59-
// do your own processing here
60-
resource.allContents.filter(Module).forEach [ module |
61-
println('''
62-
Found module «module.name»
63-
''')
64-
]
65-
}
23+
class StandaloneExample {
24+
25+
def static void main(String... args) {
26+
val injector = new YangStandaloneSetup().createInjectorAndDoEMFRegistration
27+
injector.getInstance(StandaloneExample).run(args)
28+
}
29+
30+
@Inject XtextResourceSet resourceSet
31+
@Inject IResourceValidator validator
32+
boolean hasErrors = false
33+
34+
def void run(String... args) {
35+
addFile(new File(args.head))
36+
resourceSet.resources.forEach [ resource |
37+
EcoreUtil.resolveAll(resource)
38+
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
39+
issues.forEach [ issue |
40+
hasErrors = hasErrors || issue.severity === Severity.ERROR
41+
System.err.println(issue)
42+
]
43+
]
44+
if(!hasErrors) {
45+
resourceSet.resources.forEach [
46+
generate
47+
]
48+
}
49+
}
50+
51+
def void addFile(File file) {
52+
if(file.isDirectory)
53+
file.listFiles.forEach[ addFile ]
54+
else if(file.name.endsWith('.yang'))
55+
resourceSet.getResource(URI.createURI(file.toURI.toString), true)
56+
}
57+
58+
def generate(Resource resource) {
59+
// do your own processing here
60+
resource.allContents.filter(Module).forEach [ module |
61+
println('''
62+
Found module «module.name»
63+
''')
64+
]
65+
}
6666
}
6767
```
68-
A number of useful helper methods can be found in the [utils package](https://github.com/theia-ide/yang-lsp/tree/master/yang-lsp/io.typefox.yang/src/main/java/io/typefox/yang/utils)
68+
69+
A number of useful helper methods can be found in the [utils package](https://github.com/TypeFox/yang-lsp/tree/master/yang-lsp/io.typefox.yang/src/main/java/io/typefox/yang/utils)
6970

7071
Here is sample `build.gradle` to build the above class:
7172

7273
```groovy
7374
buildscript {
74-
repositories.jcenter()
75-
dependencies {
76-
classpath 'org.xtext:xtext-gradle-plugin:1.0.19'
77-
}
75+
repositories.jcenter()
76+
dependencies {
77+
classpath 'org.xtext:xtext-gradle-plugin:1.0.19'
78+
}
7879
}
7980
8081
repositories {
8182
jcenter()
82-
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
83+
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
8384
}
8485
8586
apply plugin: 'org.xtext.xtend'
@@ -90,7 +91,7 @@ apply plugin: 'maven'
9091
group = 'io.typefox.yang'
9192
version = '0.1.0-SNAPSHOT'
9293
93-
dependencies {
94+
dependencies {
9495
compile 'io.typefox.yang:io.typefox.yang:0.1.0-SNAPSHOT'
9596
compile 'org.eclipse.xtext:org.eclipse.xtext:2.13.0'
9697
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.13.0'

0 commit comments

Comments
 (0)