Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
RohanVashisht1234 committed Jun 20, 2024
1 parent 3bf7eec commit e894669
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 19 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion src/codeFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vscode from "vscode";

export default function formatCurrentDocument(): void {
export function formatCurrentDocument(): void {
let editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (editor !== undefined && editor.document.languageId === "bend") {
var x: vscode.Terminal = vscode.window.createTerminal("Formatter");
Expand All @@ -18,3 +18,11 @@ export default function formatCurrentDocument(): void {
vscode.window.showErrorMessage("No Bend file is open in the editor");
}
}

export function main(): vscode.Disposable {
return vscode.languages.registerDocumentFormattingEditProvider("bend", {
provideDocumentFormattingEdits(): vscode.ProviderResult<any> {
formatCurrentDocument();
},
});
}
29 changes: 11 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
import vscode from "vscode";
import generateFiles from "./generateFiles";
import formatCurrentDocument from "./codeFormatter";
import * as formatter from "./codeFormatter";
import fileRunners from "./fileRunners";
import installBend from "./installBend";
import BendTreeDataProvider from "./bendTreeDataProvider";
import { LanguageClient } from 'vscode-languageclient/node';
import runLSP from "./lsp";
import * as lsp from "./lsp/main";


let client: LanguageClient;

function main(context: { subscriptions: vscode.Disposable[] }): void {
function main(): vscode.Disposable {
const bendTreeDataProvider: BendTreeDataProvider = new BendTreeDataProvider();

runLSP();

context.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider("bend", {
provideDocumentFormattingEdits(): vscode.ProviderResult<any> {
formatCurrentDocument();
},
}),
return (
vscode.window.registerTreeDataProvider("bendView", bendTreeDataProvider),
vscode.commands.registerCommand("runBendFile", () => fileRunners("run")),
vscode.commands.registerCommand("runParallel", () => fileRunners("run-c")),
vscode.commands.registerCommand("runUnParallel", () => fileRunners("run")),
vscode.commands.registerCommand("formatBend", () =>
formatCurrentDocument()
formatter.formatCurrentDocument()
),
vscode.commands.registerCommand("installBend", () => installBend()),
vscode.commands.registerCommand("desugar", () =>
Expand All @@ -48,4 +36,9 @@ function main(context: { subscriptions: vscode.Disposable[] }): void {
);
}

exports.activate = main;

function _start(context: vscode.ExtensionContext): void {
context.subscriptions.push(main(), formatter.main(), lsp.main());
}

exports.activate = _start;
11 changes: 11 additions & 0 deletions src/lsp/completionItemCreator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import vscode from "vscode";

export default function ci(label: string, details: string, kind: vscode.CompletionItemKind): vscode.CompletionItem {
const completionItem: vscode.CompletionItem = new vscode.CompletionItem(label);
completionItem.insertText = label;
completionItem.label = label;
completionItem.kind = kind;
completionItem.detail = details;
completionItem.documentation = new vscode.MarkdownString(details);
return completionItem;
}
50 changes: 50 additions & 0 deletions src/lsp/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*==============================================================================
*
* Main file (entry point for the bend lsp)
*
* - This is a temporary lsp being released until the wasm release of rust based
* bend-lsp
*
* =============================================================================
*/
import vscode from "vscode";
import ci from "./completionItemCreator";


// starting point for the lsp
export function main(): vscode.Disposable {
return vscode.languages.registerCompletionItemProvider(
{ scheme: 'file', language: 'bend' }, // Change 'plaintext' to your target language
{
provideCompletionItems(): vscode.CompletionItem[] {
// Create a simple completion item

return [
ci("def", "`def` is a keyword used to define a function or method.", vscode.CompletionItemKind.Keyword),
ci("switch", "`switch` is a keyword used to create a switch statement for multi-branch conditionals.", vscode.CompletionItemKind.Keyword),
ci("case", "`case` is a keyword used to define a branch in a switch statement.", vscode.CompletionItemKind.Keyword),
ci("return", "`return` is a keyword used to exit a function and return a value.", vscode.CompletionItemKind.Keyword),
ci("if", "`if` is a keyword used for conditional branching.", vscode.CompletionItemKind.Keyword),
ci("else", "`else` is a keyword used to provide an alternative branch in a conditional.", vscode.CompletionItemKind.Keyword),
ci("when", "`when` is a keyword used to specify conditions in pattern matching.", vscode.CompletionItemKind.Keyword),
ci("match", "`match` is a keyword used for pattern matching against values.", vscode.CompletionItemKind.Keyword),
ci("λ", "`λ` is a literal used to define bend code.", vscode.CompletionItemKind.Operator),
ci("Some", "`Some` is a keyword used to represent a value in an option type.", vscode.CompletionItemKind.Keyword),
ci("data", "`data` is a keyword used to define a data type.", vscode.CompletionItemKind.Keyword),
ci("let", "`let` is a keyword used to bind a value to a variable.", vscode.CompletionItemKind.Keyword),
ci("use", "`use` is a keyword used to bring modules or values into scope.", vscode.CompletionItemKind.Keyword),
ci("object", "`object` is a keyword used to define an object or an instance of a class.", vscode.CompletionItemKind.Keyword),
ci("fold", "`fold` is a keyword used to reduce a collection to a single value using a binary operation.", vscode.CompletionItemKind.Keyword),
ci("open", "`open` is a keyword used to open a file.", vscode.CompletionItemKind.Keyword),
ci("do", "`do` is a keyword used to start a block of expressions.", vscode.CompletionItemKind.Keyword),
ci("bind", "`bind` is a keyword used in monadic operations to chain computations.", vscode.CompletionItemKind.Keyword),
ci("Name", "`Name` is a keyword used to define a named entity.", vscode.CompletionItemKind.Keyword),
ci("identity", "`identity` is a keyword used to represent a function that returns its argument.", vscode.CompletionItemKind.Keyword),
ci("Bool", "`Bool` is a keyword used to define a boolean data type.", vscode.CompletionItemKind.Keyword),
ci("ask", "`ask` is a keyword used to retrieve a value from a context or environment.", vscode.CompletionItemKind.Keyword),
ci("with", "`with` is a keyword used to introduce a block where certain bindings are in scope.", vscode.CompletionItemKind.Keyword),
];
}
},
);
}

0 comments on commit e894669

Please sign in to comment.