Skip to content

Commit

Permalink
Refactoring code to match bash-language-server
Browse files Browse the repository at this point in the history
  - Can parse active document
  - Logging functionality
  • Loading branch information
AnHeuermann committed Dec 14, 2023
1 parent aa3e113 commit e6dae18
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 228 deletions.
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"typescript.tsc.autoDetect": "off",
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
"source.fixAll.eslint": "explicit"
},
"cSpell.words": [
"Karabel"
]
}
45 changes: 45 additions & 0 deletions server/src/analyzer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2023 Andreas Heuermann, Osman Karabel
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as LSP from 'vscode-languageserver/node';
import { TextDocument } from 'vscode-languageserver-textdocument';

import { Query } from 'web-tree-sitter';
import Parser = require('web-tree-sitter');

import { logger } from './util/logger';

type AnalyzedDocument = {
document: TextDocument;
tree: Parser.Tree
}

export default class Analyzer {
private parser: Parser;
private uriToAnalyzedDocument: Record<string, AnalyzedDocument | undefined> = {};

constructor (parser: Parser) {
this.parser = parser;
}

public analyze(document: TextDocument): LSP.Diagnostic[] {
logger.debug('analyze:');

const diagnostics: LSP.Diagnostic[] = [];
const fileContent = document.getText();
const uri = document.uri;

const tree = this.parser.parse(fileContent);
logger.debug(tree.rootNode.toString());

// Update saved analysis for document uri
this.uriToAnalyzedDocument[uri] = {
document,
tree
};

return diagnostics;
}
}
5 changes: 5 additions & 0 deletions server/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2023 Andreas Heuermann, Osman Karabel
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as Parser from 'web-tree-sitter';

/**
Expand Down
Loading

0 comments on commit e6dae18

Please sign in to comment.