mirror of
https://github.com/jlengrand/elm-language-client-vscode.git
synced 2026-03-10 08:11:17 +00:00
Steps toward parsing the correct elm files
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -65,7 +65,7 @@
|
||||
"compounds": [
|
||||
{
|
||||
"name": "Client + Server",
|
||||
"configurations": ["Launch Client", "Attach to Server"]
|
||||
"configurations": ["Launch Client", "Attach to Server 6010"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
var glob = require("glob");
|
||||
import * as Parser from "tree-sitter";
|
||||
// tslint:disable-next-line no-duplicate-imports
|
||||
import { Point, SyntaxNode, Tree } from "tree-sitter";
|
||||
@@ -5,12 +6,11 @@ import * as TreeSitterElm from "tree-sitter-elm";
|
||||
import {
|
||||
DidChangeTextDocumentParams,
|
||||
DidCloseTextDocumentParams,
|
||||
DidOpenTextDocumentParams,
|
||||
IConnection,
|
||||
TextDocumentIdentifier,
|
||||
TextDocumentItem,
|
||||
VersionedTextDocumentIdentifier,
|
||||
} from "vscode-languageserver";
|
||||
import URI from "vscode-uri";
|
||||
import { IForest } from "../forest";
|
||||
import { Position } from "../position";
|
||||
|
||||
@@ -18,10 +18,12 @@ export class ASTProvider {
|
||||
private connection: IConnection;
|
||||
private forest: IForest;
|
||||
private parser: Parser;
|
||||
private elmWorkspace: URI;
|
||||
|
||||
constructor(connection: IConnection, forest: IForest) {
|
||||
constructor(connection: IConnection, forest: IForest, elmWorkspace: URI) {
|
||||
this.connection = connection;
|
||||
this.forest = forest;
|
||||
this.elmWorkspace = elmWorkspace;
|
||||
this.parser = new Parser();
|
||||
try {
|
||||
this.parser.setLanguage(TreeSitterElm);
|
||||
@@ -29,18 +31,33 @@ export class ASTProvider {
|
||||
this.connection.console.info(error.toString());
|
||||
}
|
||||
|
||||
this.connection.onDidOpenTextDocument(this.handleOpenTextDocument);
|
||||
this.connection.onDidChangeTextDocument(this.handleChangeTextDocument);
|
||||
this.connection.onDidCloseTextDocument(this.handleCloseTextDocument);
|
||||
|
||||
this.initalizeWorkspace();
|
||||
}
|
||||
|
||||
protected handleOpenTextDocument = async (
|
||||
params: DidOpenTextDocumentParams,
|
||||
): Promise<void> => {
|
||||
this.connection.console.info("Opened text document, going to parse it");
|
||||
const document: TextDocumentItem = params.textDocument;
|
||||
const tree: Tree = this.parser.parse(document.text);
|
||||
this.forest.setTree(document.uri, tree);
|
||||
protected initalizeWorkspace = async (): Promise<void> => {
|
||||
try {
|
||||
const path = this.elmWorkspace.toString(true) + "elm.json";
|
||||
this.connection.console.info(path); // output 'testing'
|
||||
const elmJson = require(path);
|
||||
const source_dirs = elmJson["source-directories"];
|
||||
source_dirs.forEach(element => {
|
||||
// Find elm files and feed them to tree sitter
|
||||
});
|
||||
} catch (error) {
|
||||
this.connection.console.info(error.toString());
|
||||
}
|
||||
// this.connection.console.info("Initializing workspace");
|
||||
// glob("**/*.elm", function(er, files) {
|
||||
// // files is an array of filenames.
|
||||
// // If the `nonull` option is set, and nothing
|
||||
// // was found, then files is ["**/*.js"]
|
||||
// // er is an error object or null.
|
||||
// const tree: Tree = this.parser.parse(document.text);
|
||||
// this.forest.setTree(document.uri, tree);
|
||||
// });
|
||||
};
|
||||
|
||||
protected handleChangeTextDocument = async (
|
||||
|
||||
@@ -46,7 +46,7 @@ export class Server implements ILanguageServer {
|
||||
elmWorkspace: URI,
|
||||
): void {
|
||||
// tslint:disable:no-unused-expression
|
||||
new ASTProvider(connection, forest);
|
||||
new ASTProvider(connection, forest, elmWorkspace);
|
||||
new FoldingRangeProvider(connection, forest);
|
||||
new CompletionProvider(connection, forest);
|
||||
new HoverProvider(connection, forest);
|
||||
|
||||
Reference in New Issue
Block a user