Skip to content

Commit 5fe3e6f

Browse files
committed
configure which languages to activate
1 parent 53e5b36 commit 5fe3e6f

9 files changed

Lines changed: 76 additions & 25 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ However the language server protocol enables swift integration into other editor
6161
Install the semantic web lsp extension ([vscode](https://marketplace.visualstudio.com/items?itemName=ajuvercr.semantic-web-lsp) or [open-vscode](https://open-vsx.org/extension/ajuvercr/semantic-web-lsp)).
6262
The extension starts the lsp from WASM and starts the vscode LSP client.
6363

64+
You can configure the LSP to disable certain languages, this is useful as SPARQL is not fully supported yet, but comes bundled in the LSP.
65+
6466
### Jetbrains
6567

6668
A zip of the Jetbrains plugin is available with the latest releases.
@@ -96,11 +98,18 @@ vim.api.nvim_create_autocmd("FileType", {
9698
name = "swls",
9799
cmd = { "swls" },
98100
root_dir = vim.fn.getcwd(),
101+
init_options = {
102+
sparql = false, -- disable sparql support
103+
-- turtle = false,
104+
-- jsonld = false,
105+
},
99106
})
100107
end,
101108
})
102109
```
103110

111+
You can configure the LSP to disable certain languages, this is useful as SPARQL is not fully supported yet, but comes bundled in the LSP.
112+
104113
<details>
105114
<summary>Instructions for configuring an autocmd to detect and assign filetypes automatically.</summary>
106115

core/src/backend.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ impl LanguageServer for Backend {
101101

102102
let server_config = ServerConfig { config, workspaces };
103103
info!("Initialize {:?}", server_config);
104+
let document_selectors: Vec<_> = [
105+
("sparql", server_config.config.sparql.unwrap_or(true)),
106+
("turtle", server_config.config.turtle.unwrap_or(true)),
107+
("jsonld", server_config.config.jsonld.unwrap_or(true)),
108+
]
109+
.into_iter()
110+
.filter(|(_, x)| *x)
111+
.map(|(x, _)| DocumentFilter {
112+
language: Some(String::from(x)),
113+
scheme: None,
114+
pattern: None,
115+
})
116+
.collect();
104117

105118
self.run(|world| {
106119
world.insert_resource(server_config);
@@ -135,28 +148,7 @@ impl LanguageServer for Backend {
135148
SemanticTokensRegistrationOptions {
136149
text_document_registration_options: {
137150
TextDocumentRegistrationOptions {
138-
document_selector: Some(vec![
139-
DocumentFilter {
140-
language: Some(String::from("turtle")),
141-
scheme: None,
142-
pattern: None,
143-
},
144-
DocumentFilter {
145-
language: Some(String::from("jsonld")),
146-
scheme: None,
147-
pattern: None,
148-
},
149-
DocumentFilter {
150-
language: Some(String::from("sparql")),
151-
scheme: None,
152-
pattern: None,
153-
},
154-
// DocumentFilter {
155-
// language: Some(String::from("sparql")),
156-
// scheme: None,
157-
// pattern: Some(String::from("*.rq")),
158-
// },
159-
]),
151+
document_selector: Some(document_selectors),
160152
}
161153
},
162154
semantic_tokens_options: SemanticTokensOptions {

core/src/components.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,17 @@ pub struct ServerConfig {
197197
pub struct Config {
198198
#[serde(default = "debug")]
199199
pub log: String,
200+
pub turtle: Option<bool>,
201+
pub jsonld: Option<bool>,
202+
pub sparql: Option<bool>,
200203
}
201204
impl Default for Config {
202205
fn default() -> Self {
203206
Self {
204207
log: "debug".to_string(),
208+
turtle: None,
209+
jsonld: None,
210+
sparql: None,
205211
}
206212
}
207213
}

lang-jsonld/src/ecs/parse.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ pub fn parse_source(
2626
pub fn parse_jsonld_system(
2727
query: Query<(Entity, &Source, &Tokens, &Label), (Changed<Tokens>, With<JsonLd>)>,
2828
mut commands: Commands,
29+
config: Res<ServerConfig>,
2930
) {
31+
if !config.config.jsonld.unwrap_or(true) {
32+
return;
33+
}
3034
for (entity, source, tokens, label) in &query {
3135
let (jsonld, es) = parse(source.as_str(), tokens.0.clone());
3236
info!("{} triples ({} errors)", label.0, es.len());

lang-sparql/src/ecs/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ fn parse_sparql_system(
5656
query: Query<(Entity, &Source, &Tokens, &Label), (Changed<Tokens>, With<Sparql>)>,
5757
mut commands: Commands,
5858
mut old: Local<HashMap<String, (Vec<Spanned<Token>>, Context)>>,
59+
config: Res<ServerConfig>,
5960
) {
61+
if !config.config.sparql.unwrap_or(true) {
62+
return;
63+
}
6064
for (entity, source, tokens, label) in &query {
6165
let (ref mut old_tokens, ref mut context) = old.entry(label.to_string()).or_default();
6266

lang-turtle/src/ecs/parse.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ pub fn parse_turtle_system(
3434
>,
3535
mut commands: Commands,
3636
mut old: Local<HashMap<String, (Vec<Spanned<Token>>, Context)>>,
37+
config: Res<ServerConfig>,
3738
) {
39+
if !config.config.turtle.unwrap_or(true) {
40+
return;
41+
}
3842
for (entity, source, tokens, label, open) in &query {
3943
let (ref mut old_tokens, ref mut context) = old.entry(label.to_string()).or_default();
4044
context.setup_current_to_prev(

lsp-web/packages/vscode/package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"displayName": "semantic web lsp",
77
"description": "A language server for semantic web standards",
8-
"version": "0.0.8",
8+
"version": "0.0.9",
99
"icon": "favicon.png",
1010
"engines": {
1111
"vscode": "^1.90.0"
@@ -93,6 +93,21 @@
9393
"type": "boolean",
9494
"default": false,
9595
"description": "Log debug information."
96+
},
97+
"swls.turtle": {
98+
"type": "boolean",
99+
"default": true,
100+
"description": "Enable Turtle Language."
101+
},
102+
"swls.jsonld": {
103+
"type": "boolean",
104+
"default": true,
105+
"description": "Enable JSON-LD Language."
106+
},
107+
"swls.sparql": {
108+
"type": "boolean",
109+
"default": true,
110+
"description": "Enable SPARQL Language."
96111
}
97112
}
98113
}

lsp-web/packages/vscode/shape.ttl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
2+
@prefix sh: <http://www.w3.org/ns/shacl#>.
3+
4+
[ ] a sh:NodeShape;
5+
sh:targetClass foaf:Person;
6+
sh:property [
7+
sh:path foaf:name;
8+
sh:minCount 1;
9+
].
10+

lsp-web/packages/vscode/src/web/extension.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
MessageTransports,
1212
} from "vscode-languageclient";
1313
import * as rpc from "vscode-jsonrpc";
14+
import { json } from "stream/consumers";
1415

1516
class ReadableS {
1617
readonly onError: rpc.Event<Error>;
@@ -116,7 +117,6 @@ class LanguageClient extends BaseLanguageClient {
116117

117118
// Your extension is activated the very first time the command is executed
118119
export async function activate() {
119-
120120
const channel = vscode.window.createOutputChannel("swls");
121121
logger.init(
122122
(st) => channel.appendLine(st.trim()),
@@ -140,6 +140,9 @@ export async function activate() {
140140
logger.set(debug);
141141

142142
logger.info("Debug is on " + debug);
143+
const turtle = vscode.workspace.getConfiguration().get("swls.turtle");
144+
const jsonld = vscode.workspace.getConfiguration().get("swls.jsonld");
145+
const sparql = vscode.workspace.getConfiguration().get("swls.sparql");
143146

144147
vscode.workspace.onDidChangeConfiguration((event) => {
145148
// Check if the specific setting has changed
@@ -171,7 +174,11 @@ export async function activate() {
171174
},
172175
],
173176
synchronize: {},
174-
initializationOptions: {},
177+
initializationOptions: {
178+
sparql,
179+
turtle,
180+
jsonld
181+
},
175182
};
176183

177184
const client = new LanguageClient(

0 commit comments

Comments
 (0)