diff --git a/lsp-bin/linux/arm64 b/archive/lsp-bin/linux/arm64 similarity index 100% rename from lsp-bin/linux/arm64 rename to archive/lsp-bin/linux/arm64 diff --git a/lsp-bin/linux/x64 b/archive/lsp-bin/linux/x64 similarity index 100% rename from lsp-bin/linux/x64 rename to archive/lsp-bin/linux/x64 diff --git a/lsp-bin/linux/x86 b/archive/lsp-bin/linux/x86 similarity index 100% rename from lsp-bin/linux/x86 rename to archive/lsp-bin/linux/x86 diff --git a/lsp-bin/macos/arm64 b/archive/lsp-bin/macos/arm64 similarity index 100% rename from lsp-bin/macos/arm64 rename to archive/lsp-bin/macos/arm64 diff --git a/lsp-bin/macos/x64 b/archive/lsp-bin/macos/x64 similarity index 100% rename from lsp-bin/macos/x64 rename to archive/lsp-bin/macos/x64 diff --git a/lsp-bin/macos/x86 b/archive/lsp-bin/macos/x86 similarity index 100% rename from lsp-bin/macos/x86 rename to archive/lsp-bin/macos/x86 diff --git a/lsp-bin/windows/arm64.exe b/archive/lsp-bin/windows/arm64.exe similarity index 100% rename from lsp-bin/windows/arm64.exe rename to archive/lsp-bin/windows/arm64.exe diff --git a/lsp-bin/windows/x64.exe b/archive/lsp-bin/windows/x64.exe similarity index 100% rename from lsp-bin/windows/x64.exe rename to archive/lsp-bin/windows/x64.exe diff --git a/lsp-bin/windows/x86.exe b/archive/lsp-bin/windows/x86.exe similarity index 100% rename from lsp-bin/windows/x86.exe rename to archive/lsp-bin/windows/x86.exe diff --git a/src/lsp.ts b/archive/lsp.ts.old similarity index 100% rename from src/lsp.ts rename to archive/lsp.ts.old diff --git a/src/codeFormatter.ts b/src/codeFormatter.ts index a68bb81..9eb9796 100644 --- a/src/codeFormatter.ts +++ b/src/codeFormatter.ts @@ -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"); @@ -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 { + formatCurrentDocument(); + }, + }); +} diff --git a/src/extension.ts b/src/extension.ts index aa49fe5..c1431c1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { - 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", () => @@ -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; diff --git a/src/lsp/completionItemCreator.ts b/src/lsp/completionItemCreator.ts new file mode 100644 index 0000000..e879673 --- /dev/null +++ b/src/lsp/completionItemCreator.ts @@ -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; +} \ No newline at end of file diff --git a/src/lsp/main.ts b/src/lsp/main.ts new file mode 100644 index 0000000..2aa128d --- /dev/null +++ b/src/lsp/main.ts @@ -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), + ]; + } + }, + ); +}