Skip to content

Commit

Permalink
Add Oberon VSCode extension
Browse files Browse the repository at this point in the history
  • Loading branch information
schierlm committed Jan 1, 2022
1 parent f5f66f3 commit 9c6dc57
Show file tree
Hide file tree
Showing 17 changed files with 5,342 additions and 0 deletions.
24 changes: 24 additions & 0 deletions vscode-oberon-lsp/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
7 changes: 7 additions & 0 deletions vscode-oberon-lsp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
out
dist
node_modules
.vscode-test/
*.vsix
.vscode/*
!.vscode/*.json.default
11 changes: 11 additions & 0 deletions vscode-oberon-lsp/.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
const fs = require('fs');
function copyFromDefault(p) {
if (!fs.existsSync(p)) {
const defaultFile = `${p}.default`;
if (fs.existsSync(defaultFile)) {
fs.copyFileSync(defaultFile, p);
}
}
}
['.vscode/settings.json', '.vscode/tasks.json', '.vscode/launch.json'].map(copyFromDefault);
18 changes: 18 additions & 0 deletions vscode-oberon-lsp/.vscode/launch.json.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
11 changes: 11 additions & 0 deletions vscode-oberon-lsp/.vscode/settings.json.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.exclude": {
"out": false,
"dist": false
},
"search.exclude": {
"out": true,
"dist": true
},
"typescript.tsc.autoDetect": "off",
}
29 changes: 29 additions & 0 deletions vscode-oberon-lsp/.vscode/tasks.json.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": [
"$ts-webpack-watch"
],
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "compile",
"group": "build",
"problemMatcher": [],
"label": "npm: compile",
"detail": "webpack"
}
]
}
14 changes: 14 additions & 0 deletions vscode-oberon-lsp/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.vscode/**
.vscode-test/**
test/**
out/**
node_modules/**
src/**
.gitignore
.yarnrc
webpack.config.js
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
10 changes: 10 additions & 0 deletions vscode-oberon-lsp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [0.9.0] - 2021-12-29
- Initial (beta) release
22 changes: 22 additions & 0 deletions vscode-oberon-lsp/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2021, 2022 Michael Schierl
Copyright (c) Microsoft Corporation (from https://github.com/Microsoft/vscode-extension-samples)
Copyright (c) 2017 Colby Russell (from https://marketplace.visualstudio.com/items?itemName=colbyrussell.vscode-oberon-support)
Copyright (c) 2013 Vladislav Folts (from https://github.com/vladfolts/oberonjs)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
83 changes: 83 additions & 0 deletions vscode-oberon-lsp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Oberon Language support with LSP wrapper

This package brings Oberon syntax highlighting to VSCode. In addition, it can
invoke an Oberon Language Server written in Java to provide code folding, auto
completion, reformatting, reference navigation and more. The Language server
will then connect to a Language Server Protocol Helper, which may (depending on
the exact language dialect) either be written as a native binary, or as a
Project Oberon disk image run inside the Oberon FPGA Emulator (written in Java).
The idea is to implement the Language Server Protocol helper in the language it
(or its compiler) is written in, to leverage synergies from the already existing
lexer and parser for the language.

## Features

- Supported file extensions `.Mod`, `.ob`, `.ob07` and `.Mod.txt`
- Basic syntax highlighting (TextMate grammar)
- Comment detection (no nested comments), bracket insertion and matching
- Auto closing brackets, strings and comments
- Surrounding with brackets and strings
- Automatic indentation after certain words (partially disabled since the
complex expression seems to freeze VSCode sometimes)
- Optionally calling out to an LSP language server for more features:
* Compiler warnings and errors
* Unused variables
* Outline and folding
* Semantic highlighting
* Jump to definition / references / call hierarchy
* Autocompletion
* Formatting
* Rename non-exported variable/function in file
* Hover for function definition; function signature help
* Cache mode / Workspace Folder support (if disabled, only currently open
files will get parsed/checked)

## Requirements

In case you want to use the language server, you have to download and install it
separately and configure its path (`oberonLsp.languageServer.location`). You
will also need a version of Java (8, 11 or 17) installed and configure your Java
path in case it is not in `$PATH` (`oberonLsp.languageServer.javaLocation`).

Also, the language server needs to be explicitly enabled
(`oberonLsp.languageServer.activate`), so if you do not want to use the language
server, nothing special needs to be done.

## Extension Settings

This extension contributes the following settings:

* `myExtension.enable`: enable/disable this extension
* `myExtension.thing`: set to `blah` to do something
* `oberonLsp.languageServer.activate`: Activate the language server
* `oberonLsp.languageServer.cache.activate`: Activate the cache mode.
* `oberonLsp.languageServer.cache.directory`: Cache directory relative to
workspace folder, by default `.vscode/lsp-cache`.
* `oberonLsp.languageServer.javaLocation`: Location of your Java binary
* `oberonLsp.languageServer.location`: Location (directory) of your language server
* `oberonLsp.languageServer.launchType`: Which Oberon dialect you want to use
with the language server:
* `po2013`: Project Oberon 2013
* `extended`: Extended Oberon
* `retro`: Oberon Retro compiler
* `a2`: A2 / Bluebottle (needs native compiler helper binary). You can
configure the compiler command line switches in
`oberonLsp.languageServer.launchTypeA2.switches` and additional symbol path
in `oberonLsp.languageServer.launchTypeA2.symbolpath`.
* `other1`: Any other system, give arguments in
`oberonLsp.languageServer.other1Arguments` (default: same as `po2013`)
* `other2`: Any other system, give arguments in
`oberonLsp.languageServer.other2Arguments` (default: Connect to language
server helper running in Oberon emulator)
* `other3`: Any other system, give arguments in
`oberonLsp.languageServer.other2Arguments` (default: run Language Server
under remote Java debugger)
* `oberonLsp.languageServer.modifiedDiskImage`: Path to alternate disk image
for `po2013` (useful if it contains symbol files for files not present in
source code form in the workspace)

## Release Notes

### 0.9.0

Initial (beta) release.
45 changes: 45 additions & 0 deletions vscode-oberon-lsp/oberon-language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"comments": {
"blockComment": [ "(*", "*)" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"colorizedBracketPairs": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "$", "close": "$", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "(*", "close": " *", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["$", "$"],
["\"", "\""]
],
"wordPattern": "[+-]?[0-9]+([.][0-9]*([DE][+-]?[0-9]+)?)?|[0-9][0-9A-F]*[HRX]|[A-Za-z][A-Za-z0-9]*",
"onEnterRules": [
{
"beforeText": "^([^\"']|\"[^\"']*\"|'[^\"']*)*\\b(BEGIN|THEN|DO|ELSE)\\s*$",
"action": {
"indent": "indent"
}
}
]
/* Removed for now. Those seem to freeze VS Code when pasting large amounts of code
"indentationRules": {
"unIndentedLinePattern": "^.*\\(\\*([^*]*|\\*[^)])*$",
"increaseIndentPattern": "^([^\"']|\"[^\"']*\"|'[^\"']*)*\\b(BEGIN|THEN|DO|ELSE)\\s*$",
"decreaseIndentPattern": "^\\s*(ELSE|ELSIF|END|RETURN)\\b.*$"
}*/
}
104 changes: 104 additions & 0 deletions vscode-oberon-lsp/oberon.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"fileTypes": [
"Mod",
"ob",
"ob07"
],
"name": "Oberon",
"patterns": [
{
"match": "\\b(FOR|REPEAT|IF|ELSIF|UNTIL|WHILE|DO|ELSE|THEN|CASE|BY|RETURN|TO)\\b",
"name": "keyword.control.oberon"
},
{
"match": "\\b(IS|DIV|MOD|OR|IN)\\b",
"name": "keyword.operator.oberon"
},
{
"match": "\\b(IMPORT|BEGIN|TYPE|CONST|MODULE|VAR|PROCEDURE|END)\\b",
"name": "keyword.other.oberon"
},
{
"match": "\\b(POINTER|RECORD|ARRAY|MAP|OF)\\b",
"name": "storage.type.oberon"
},
{
"match": "\\b(FALSE|NIL|TRUE)\\b",
"name": "constant.language.oberon"
},
{
"match": "\\b(ABS|ASR|CHR|FLT|INC|LSL|NEW|ROR|ASSERT|DEC|EXCL|FLOOR|INCL|LEN|ODD|ORD|PACK|UNPK)\\b",
"name": "support.function.oberon"
},
{
"match": "\\b(CHAR|REAL|BYTE|INTEGER|SET|BOOLEAN)\\b",
"name": "support.type.oberon"
},
{
"match": "\\b([0-9]+([.][0-9]*([DE][+-]?[0-9]+)?)?|[0-9][0-9A-F]*[HR])\\b",
"name": "constant.numeric.oberon"
},
{
"begin": "\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.oberon"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.oberon"
}
},
"name": "string.quoted"
},
{
"begin": "'",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.single.oberon"
}
},
"end": "'",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.single.oberon"
}
},
"name": "string.quoted.single"
},
{
"begin": "\\$",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.hex.oberon"
}
},
"end": "\\$",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.hex.oberon"
}
},
"name": "string.quoted.hex"
},
{
"match": "\\b([0-9][0-9A-F]*[X])\\b",
"name": "string.other.oberon"
},
{
"begin": "\\(\\*",
"captures": {
"0": {
"name": "punctuation.definition.comment.oberon"
}
},
"end": "\\*\\)",
"name": "comment.block.oberon"
}
],
"scopeName": "source.oberon",
"uuid": "2AA78D88-FD4B-11E6-937E-CFB8A4F7030F"
}
Loading

0 comments on commit 9c6dc57

Please sign in to comment.