Skip to content

Commit

Permalink
update rainlang v4
Browse files Browse the repository at this point in the history
- remove meta debounce
  • Loading branch information
rouzwelt committed Oct 14, 2023
1 parent c60b29a commit 88b857c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 49 deletions.
39 changes: 19 additions & 20 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"url": "https://github.com/rainprotocol/rainlang-vscode/issues"
},
"dependencies": {
"@rainprotocol/rainlang": "github:rainprotocol/rainlang#bb4a348a7d71cb7013420a2a14a5ffb5ad3ff8f4",
"@rainprotocol/rainlang": "^4.1.0",
"vscode-languageserver": "^8.1.0"
}
}
34 changes: 20 additions & 14 deletions server/src/browserServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ connection.onInitialize(async(params: InitializeParams) => {

langServices = getRainLanguageServices({
clientCapabilities,
metaStore
metaStore,
noMetaSearch: true
});

const result: InitializeResult = {
Expand Down Expand Up @@ -129,21 +130,19 @@ connection.onDidChangeConfiguration(async() => {
}
}
if (settings?.subgraphs) await metaStore.addSubgraphs(settings.subgraphs);
documents.all().forEach(async(v) => {
if (v.languageId === "rainlang") validate(v);
});
documents.all().forEach(async(v) => { validate(v, v.getText(), v.version); });
});

documents.onDidOpen(v => {
if (v.document.languageId === "rainlang") validate(v.document);
validate(v.document, v.document.getText(), v.document.version);
});

documents.onDidClose(v => {
connection.sendDiagnostics({ uri: v.document.uri, diagnostics: []});
});

documents.onDidChangeContent(change => {
if (change.document.languageId === "rainlang") validate(change.document);
validate(change.document, change.document.getText(), change.document.version);
});

connection.onCompletion(params => {
Expand All @@ -170,8 +169,10 @@ connection.onHover(params => {
connection.languages.semanticTokens.on(async(e: SemanticTokensParams) => {
let data: number[];
const _td = documents.get(e.textDocument.uri);
if (_td) {
const _rd = await RainDocument.create(_td, metaStore);
if (_td && _td.languageId === "rainlang") {
const _rd = new RainDocument(_td, metaStore);
(_rd as any)._shouldSearch = false;
await _rd.parse();
let _lastLine = 0;
let _lastChar = 0;
data = _rd.bindings.filter(v =>
Expand Down Expand Up @@ -273,10 +274,15 @@ async function getSetting() {
}

// validate a document
async function validate(textDocument: TextDocument): Promise<void> {
// Send the computed diagnostics to VSCode.
connection.sendDiagnostics({
uri: textDocument.uri,
diagnostics: await langServices.doValidate(textDocument)
});
async function validate(textDocument: TextDocument, text: string, version: number): Promise<void> {
if (textDocument.languageId === "rainlang") {
const diagnostics = await langServices.doValidate(
TextDocument.create("untitled", "rainlang", 0, text)
);
// check version of the text document before sending the diagnostics to VSCode
if (version === textDocument.version) connection.sendDiagnostics({
uri: textDocument.uri,
diagnostics
});
}
}
34 changes: 20 additions & 14 deletions server/src/nodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ connection.onInitialize(async(params) => {

langServices = getRainLanguageServices({
clientCapabilities,
metaStore
metaStore,
noMetaSearch: true
});

const result: InitializeResult = {
Expand Down Expand Up @@ -129,21 +130,19 @@ connection.onDidChangeConfiguration(async() => {
}
}
if (settings?.subgraphs) await metaStore.addSubgraphs(settings.subgraphs);
documents.all().forEach(async(v) => {
if (v.languageId === "rainlang") validate(v);
});
documents.all().forEach(async(v) => { validate(v, v.getText(), v.version); });
});

documents.onDidOpen(v => {
if (v.document.languageId === "rainlang") validate(v.document);
validate(v.document, v.document.getText(), v.document.version);
});

documents.onDidClose(v => {
connection.sendDiagnostics({ uri: v.document.uri, diagnostics: []});
});

documents.onDidChangeContent(change => {
if (change.document.languageId === "rainlang") validate(change.document);
validate(change.document, change.document.getText(), change.document.version);
});

connection.onDidChangeWatchedFiles(_change => {
Expand Down Expand Up @@ -175,8 +174,10 @@ connection.onHover(params => {
connection.languages.semanticTokens.on(async(e: SemanticTokensParams) => {
let data: number[];
const _td = documents.get(e.textDocument.uri);
if (_td) {
const _rd = await RainDocument.create(_td, metaStore);
if (_td && _td.languageId === "rainlang") {
const _rd = new RainDocument(_td, metaStore);
(_rd as any)._shouldSearch = false;
await _rd.parse();
let _lastLine = 0;
let _lastChar = 0;
data = _rd.bindings.filter(v =>
Expand Down Expand Up @@ -278,10 +279,15 @@ async function getSetting() {
}

// validate a document
async function validate(textDocument: TextDocument): Promise<void> {
// Send the computed diagnostics to VSCode.
connection.sendDiagnostics({
uri: textDocument.uri,
diagnostics: await langServices.doValidate(textDocument)
});
async function validate(textDocument: TextDocument, text: string, version: number): Promise<void> {
if (textDocument.languageId === "rainlang") {
const diagnostics = await langServices.doValidate(
TextDocument.create("untitled", "rainlang", 0, text)
);
// check version of the text document before sending the diagnostics to VSCode
if (version === textDocument.version) connection.sendDiagnostics({
uri: textDocument.uri,
diagnostics
});
}
}

0 comments on commit 88b857c

Please sign in to comment.