Skip to content
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

Language server #117

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6a6967c
Merge branch 'master' of https://github.com/BarryNolte/d2-vscode
BarryNolte Jun 16, 2023
a35eeac
Work In Progress
BarryNolte Jun 28, 2023
86faaa8
Bootstraping Language Server
BarryNolte Jul 7, 2023
8268aea
Change fixed path to path from settings file
BarryNolte Jul 8, 2023
4935810
Fixed up d2 path, again
BarryNolte Jul 8, 2023
689a24a
Checkpoint - File Import Completion Working
BarryNolte Jul 13, 2023
9958431
Checkpoint - File Import Completion Working
BarryNolte Jul 13, 2023
eddc7f7
CheckPoint
BarryNolte Jul 15, 2023
355fb28
Checkpoint
BarryNolte Jul 23, 2023
f5af735
Reconfigured directory structure
BarryNolte Jul 24, 2023
c8fb692
Checkpoint
BarryNolte Jul 25, 2023
74118df
Pre-Code Cleanup
BarryNolte Jul 29, 2023
6eaea67
Merge branch 'terrastruct:master' into LanguageServer
BarryNolte Aug 2, 2023
0a7c2c0
First Language Server PR
BarryNolte Aug 2, 2023
06899b9
Merge branch 'LanguageServer' of https://github.com/BarryNolte/d2-vsc…
BarryNolte Aug 2, 2023
6594075
Final push before pull request
BarryNolte Aug 8, 2023
7df1372
Get CI to work (maybe...)
BarryNolte Aug 10, 2023
313251f
Try again to get ci to work
BarryNolte Aug 10, 2023
748398b
Code Review Fixes
BarryNolte Nov 3, 2023
ccbe41f
Code review updates and general tweaks and fixes.
BarryNolte Nov 8, 2023
6b9dc75
Change prettier version to work with CI
BarryNolte Nov 8, 2023
9a20650
Reworked autocomplete, file linking and markdown embedding.
BarryNolte Dec 30, 2023
d8eaeee
Code clean-up
BarryNolte Dec 30, 2023
6b86fc1
Code Cleanup
BarryNolte Jan 1, 2024
ec25e38
Merge branch 'master' into LanguageServer
BarryNolte Jan 2, 2024
02fe37b
Fix formatting bugs
BarryNolte Jan 2, 2024
aeff708
Merge branch 'LanguageServer' of https://github.com/BarryNolte/d2-vsc…
BarryNolte Jan 2, 2024
c254965
eslint version mismatch
BarryNolte Jan 2, 2024
4f0ff39
Set eslint to specific version
BarryNolte Jan 2, 2024
7c95cc4
Fix for package generation
BarryNolte Feb 7, 2024
1976c65
Code review changes
BarryNolte Feb 8, 2024
909980b
Format and forgotten file
BarryNolte Feb 8, 2024
6d5aca9
Code Review Change
BarryNolte Feb 16, 2024
ed206a0
Change request was not the answer we were looking for.
BarryNolte Feb 16, 2024
b0f75cd
Work In Progress
BarryNolte Mar 21, 2024
86f1055
Update dependencies
BarryNolte Mar 30, 2024
99bbb27
Add a 'recompile' button
BarryNolte Mar 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Work In Progress
BarryNolte committed Mar 21, 2024

Verified

This commit was signed with the committer’s verified signature.
d2iq-dispatch D2iQ Dispatch
commit b0f75cd1d85641192d6b9c0896512100aa3e3917
9 changes: 5 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -3,22 +3,23 @@

"compounds": [
{
"name": "Server/Client",
"configurations": ["Attach to Server", "Launch Extension"],
"name": "1 Debug All",
"configurations": ["Extension Launch", "Server Attach"],
"stopAll": true
}
],
"configurations": [
{
"name": "Attach to Server",
"name": "Server Attach",
"port": 6009,
"timeout": 10000,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "node"
},
{
"name": "Extension Launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"name": "Launch Extension",
"outFiles": [
"${workspaceFolder}/client/dist/**/*.js",
"${workspaceFolder}/server/dist/**/*.js"
3 changes: 3 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -301,6 +301,9 @@ function startLanguageServer(): void {
);

langClient.start();
// langClient.onNotification("foo", (param: string) => {
// console.log(`OnNotification: ${param}`)
// });
}

/**
13 changes: 5 additions & 8 deletions server/src/completionHelpers.ts
Original file line number Diff line number Diff line change
@@ -122,8 +122,6 @@ export class CompletionHelper {

const node = astData.nodeAtPosition({ line: pos.line, character: charPos });

// console.info(`Node: ${charPos} -> \n${JSON.stringify(node, null, 2)}\n\n`);

if (node) {
const list: string[] = ItemTree.getListFromPath(node);

@@ -145,14 +143,13 @@ export class CompletionHelper {
static doOpenSpace(astData: AstReader, pos: Position): CompletionList {
const compItems: CompletionItem[] = [];

// THIS NEEDS SOME MORE WORK TO} DETECT WHAT COMPLETION HELPER SHOULD BE CALLED
// THIS NEEDS SOME MORE WORK TO DETECT WHICH COMPLETION HELPER SHOULD BE CALLED

const node = astData.nodeAtPosition({ line: pos.line, character: pos.character });
console.log(`Open Space: ${node}`);
// const node = astData.nodeAtPosition({ line: pos.line, character: pos.character });

for (const tItem of ItemTree.Root) {
compItems.push(CompletionItem.create(tItem.item));
}
// for (const tItem of ItemTree.Root) {
// compItems.push(CompletionItem.create(tItem.item));
// }

return CompletionList.create(compItems, false);
}
10 changes: 5 additions & 5 deletions server/src/completionTree.ts
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ export class ItemTree {
/**
*
*/
private static NumberRange(start: number, end: number): TreeItem[] {
private static NumberRangeInteger(start: number, end: number): TreeItem[] {
const tis: TreeItem[] = [];

for (let i = start; i <= end; i++) {
@@ -349,15 +349,15 @@ export class ItemTree {
new TreeItem("stroke", this.colorList),
new TreeItem("fill", this.colorList),
new TreeItem("fill-pattern", this.fillPattern),
new TreeItem("stroke-width", this.NumberRange(1, 15)),
new TreeItem("stroke-dash", this.NumberRange(0, 10)),
new TreeItem("border-radius", this.NumberRange(0, 20)),
new TreeItem("stroke-width", this.NumberRangeInteger(1, 15)),
new TreeItem("stroke-dash", this.NumberRangeInteger(0, 10)),
new TreeItem("border-radius", this.NumberRangeInteger(0, 20)),
new TreeItem("shadow", this.trueFalse),
new TreeItem("3D", this.trueFalse),
new TreeItem("multiple", this.trueFalse),
new TreeItem("double-border", this.trueFalse),
new TreeItem("font", this.fonts),
new TreeItem("font-size", this.NumberRange(8, 100)),
new TreeItem("font-size", this.NumberRangeInteger(8, 100)),
new TreeItem("font-color", this.colorList),
new TreeItem("bold", this.trueFalse),
new TreeItem("italic", this.trueFalse),
53 changes: 42 additions & 11 deletions server/src/d2Ast.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,13 @@ import {
PublishDiagnosticsParams,
} from "vscode-languageserver";

import { d2ExternalLink, d2Node, d2Range, d2StringAndRange } from "./dataContainers";
import {
d2ExternalLink,
d2Ir,
d2Node,
d2Range,
d2StringAndRange,
} from "./dataContainers";
import { Position } from "vscode-languageserver-textdocument";
import { connection } from "./server";

@@ -23,15 +29,19 @@ import { connection } from "./server";
export class AstReader {
constructor(astStr: string) {
try {
// console.log(astStr);
this.d2Info = JSON.parse(astStr);
} catch (err) {
connection.console.error("Possilble D2/VsCode version mismatch.");
connection.console.error(astStr);
}

// connection.sendNotification("foo", "bar");

this.range = this.d2Info?.Ast.range;

this.processNodes(this.d2Info?.Ast.nodes);
this.processIrFields(this.d2Info?.Ir.fields);
}

/**
@@ -40,6 +50,7 @@ export class AstReader {
private range: d2Range;
private d2Info: LSPAny;
private nodes: d2Node[] = [];
private fields: d2Ir[] = [];
private references: d2StringAndRange[] | undefined;

/**
@@ -95,16 +106,16 @@ export class AstReader {

for (const node of this.nodes) {
// Edges
if (node.hasEdges) {
for (const edge of node.Edges) {
if (edge.src.edgeNode) {
this.references.push(edge.src.edgeNode);
}
if (edge.dst.edgeNode) {
this.references.push(edge.dst.edgeNode);
}
}
}
// if (node.hasEdges) {
// for (const edge of node.Edges) {
// if (edge.src.edgeNode) {
// this.references.push(edge.src.edgeNode);
// }
// if (edge.dst.edgeNode) {
// this.references.push(edge.dst.edgeNode);
// }
// }
// }

if (node.hasKey) {
if (node.Key?.key) {
@@ -168,6 +179,10 @@ export class AstReader {
*/
private processNodes(nodes: LSPAny[]) {
for (const node of nodes ?? []) {
// It's a Comment, it's not quite a node
if (node.map_key === undefined) {
continue;
}
const n = new d2Node(node);
this.nodes.push(n);

@@ -180,6 +195,22 @@ export class AstReader {
}
}

/**
* Go through all the ir's field objects to get
* references.
*/
processIrFields(fields: LSPAny[]) {
for (const field of fields ?? []) {
const f = new d2Ir(field);
this.fields.push(f);
}

console.log("\n---------\nIR\n----------\n");
for (const f of this.fields) {
console.log(f.toString());
}
}

dump(): void {
console.log(`\n---------\nASTREADER: ${this.range.toString()}\n---------\n`);

Loading