Skip to content

Commit

Permalink
Merge pull request #1 from ELENA-LANG/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
arakov authored May 31, 2024
2 parents bb5d120 + b32c5e7 commit 0087b32
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 33 deletions.
36 changes: 5 additions & 31 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
node_modules
*.vsix
.vscode/ipch
*.code-workspace
dist/
*.exe
*.out
*.app
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

All notable changes to the "l" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# vscode-elena-lang
ELENA Language support for Visual Studio Code
# ELENA language support for Visual Studio Code

Provides [ELENA language](https://elena-lang.github.io) support for Visual Studio Code.

## Commands

- `ELENA: Compile a current file`
- `ELENA: Compile a current project`

You can access all of the above commands from the command palette (`Cmd+Shift+P`).

## License

[MIT](./LICENSE)
Binary file added icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "//",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
"blockComment": [ "/*", "*/" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""]
],
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""]
]
}
102 changes: 102 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"name": "vscode-elena-lang",
"displayName": "ELENA",
"description": "ELENA Language support for Visual Studio Code",
"icon": "icons/icon.png",
"version": "0.0.1",
"engines": {
"vscode": "^1.89.0"
},
"bugs": {
"url": "https://github.com/ELENA-LANG/vscode-elena-lang/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/ELENA-LANG/vscode-elena-lang"
},
"keywords": [
"elena-lang",
"ELENA"
],
"categories": [
"Programming Languages"
],
"l10n": "./l10n",
"contributes": {
"languages": [
{
"id": "elena",
"aliases": [
"ELENA",
"elena"
],
"extensions": [
"l",
"prj"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "elena",
"scopeName": "source.elena-lang",
"path": "./syntaxes/elena.tmLanguage.json"
}
],
"configuration": {
"title": "ELENA",
"properties": {
"elena.executablePath": {
"scope": "resource",
"type": "string",
"description": "Custom path to ELENA compiler executable (`elena-cli`)."
}
}
},
"commands": [
{
"command": "elena.compileSingleFile",
"title": "Compile the current file",
"category": "ELENA"
},
{
"command": "elena.compileProject",
"title": "Compile the current project",
"category": "ELENA"
}
],
"menus": {
"commandPalette": [
{
"command": "elena.compileSingleFile",
"when": "editorLangId == elena"
},
{
"command": "elena.compileProject",
"when": "editorLangId == elena"
}
]
}
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./"
},
"activationEvents": [
"workspaceContains:**/*.l",
"onLanguage:elena",
"onCommand:elena.compileSingleFile",
"onCommand:elena.compileProject"
],
"main": "./dist/main.js",
"devDependencies": {
"@vscode/l10n-dev": "^0.0.18",
"typescript": "^5.4.2",
"vscode": "^1.1.37"
},
"dependencies": {
"@vscode/l10n": "^0.0.10"
}
}
3 changes: 3 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extension.sayHello.title": "Hello"
}
23 changes: 23 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as vscode from 'vscode';
import { window } from 'vscode';
import { compileInTerminal } from './exec';
import { getProjectFile } from './utils';

export async function compileSingleFile(): Promise<void> {
const document : vscode.TextDocument | undefined = window?.activeTextEditor?.document;
if (document) {
await document.save();
const filePath = `"${document.fileName}"`;

compileInTerminal([filePath]);
}
}

export async function compileProject(): Promise<void> {
const projectFile : vscode.Uri | undefined = await getProjectFile();
if (projectFile) {
const filePath = `"${projectFile.fsPath}"`;

compileInTerminal([filePath]);
}
}
14 changes: 14 additions & 0 deletions src/exec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { window, Terminal } from 'vscode';
import { getExecCommand } from './utils';

let terminalWindow: Terminal | undefined = undefined;

export function compileInTerminal(args: string[]): void {
const execFile = getExecCommand();
const cmd = `${execFile} ${args.join(' ')}`;

if (!terminalWindow) terminalWindow = window.createTerminal('ELENA');

terminalWindow.show();
terminalWindow.sendText(cmd);
}
24 changes: 24 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as vscode from 'vscode';
import * as commands from './commands';

const cmds : Array<[string, () => void]> = [
[ 'elena.compileSingleFile', commands.compileSingleFile ],
[ 'elena.compileProject', commands.compileProject ]
];

/**
* This method is called when the extension is activated.
* @param context The extension context
*/
export function activate(context: vscode.ExtensionContext): void {
let output = vscode.window.createOutputChannel("elena");
output.appendLine("Starting ELENA vscode extension..");

for (var cmd of cmds) {
const disposable = vscode.commands.registerCommand(cmd[0], cmd[1]);
context.subscriptions.push(disposable);
}
}

export function deactivate(): void {
}
49 changes: 49 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
workspace,
WorkspaceConfiguration,
window,
Uri,
WorkspaceFolder,
RelativePattern
} from 'vscode';

const defaultCommand = 'elena-cli';

export function getWorkspaceFolder(uri?: Uri): WorkspaceFolder | undefined {
if (uri) {
return workspace.getWorkspaceFolder(uri);
} else if (window.activeTextEditor && window.activeTextEditor.document) {
return workspace.getWorkspaceFolder(window.activeTextEditor.document.uri);
} else if (workspace.workspaceFolders) {
return workspace.workspaceFolders[0];
}
return undefined;
}

export function getWorkspaceConfig(): WorkspaceConfiguration | undefined {
const currentWorkspaceFolder = getWorkspaceFolder();
if (currentWorkspaceFolder) {
return workspace.getConfiguration('elena', currentWorkspaceFolder.uri);
}
return undefined;
}

export function getExecCommand(): string | undefined {
const config: WorkspaceConfiguration | undefined = getWorkspaceConfig();
return config?.get('elena.executablePath', defaultCommand);
}

export async function getProjectFile(): Promise<Uri | undefined> {
const currentWorkspaceFolder = getWorkspaceFolder();
if (currentWorkspaceFolder == null) {
return undefined;
}

const pattern = new RelativePattern(currentWorkspaceFolder.uri.path, '*.prj');
const files = await workspace.findFiles(pattern);
if (files && files.length > 0) {
return files[0];
};

return undefined;
}
32 changes: 32 additions & 0 deletions syntaxes/elena.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "ELENA",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#strings"
}
],
"repository": {
"keywords": {
"patterns": [{
"name": "keyword.control.elena",
"match": "\\b(if|while|for|return)\\b"
}]
},
"strings": {
"name": "string.quoted.double.elena",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.elena",
"match": "\\\\."
}
]
}
},
"scopeName": "source.elena-lang"
}
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2022",
"outDir": "dist",
"lib": [
"ES2022",
"dom"
],
"rootDir": "src",
"strict": true,
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules/**"
]
}

0 comments on commit 0087b32

Please sign in to comment.