Skip to content

Commit

Permalink
Merge pull request #581 from ohmtech-rdi/vscode-lang-extension
Browse files Browse the repository at this point in the history
Vscode language extension
  • Loading branch information
ohmtech-rdi authored Jun 22, 2023
2 parents 141e7a4 + ee9aa3c commit ded0e9c
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 2 deletions.
7 changes: 5 additions & 2 deletions build-system/completion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def xcode (): return '--xcode'
def semihosting (): return '--semihosting'
def only_gerber (): return '--only-gerber'
def with_xcode_support (): return '--with-xcode-support'
def with_vscode_support (): return '--with-vscode-support'

def build_simulator (): return 'simulator', ZeroOrMore ([configuration, xcode])
def build_firmware (): return 'firmware', ZeroOrMore ([configuration, semihosting])
Expand All @@ -33,9 +34,9 @@ def install_bootloader (): return 'bootloader'

def setup ():
if platform.system () == 'Darwin':
return 'setup', ZeroOrMore ([with_xcode_support])
return 'setup', ZeroOrMore ([with_xcode_support, with_vscode_support])
else:
return 'setup'
return 'setup', ZeroOrMore ([with_vscode_support])
def init (): return 'init', ZeroOrMore ([name, language])
def configure (): return 'configure'
def build (): return 'build', [build_simulator, build_firmware, build_hardware]
Expand All @@ -49,6 +50,8 @@ def erbb_cli (): return 'erbb', commands

DESCRIPTION = {
'setup': 'install all dependencies',
'--with-xcode-support': 'for Xcode support',
'--with-vscode-support': 'for Visual Studio Code support',
'init': 'create a new project in current directory',
'--name': 'name of project, random name if not specified',
'--language': 'the language to use, defaults to c++',
Expand Down
8 changes: 8 additions & 0 deletions build-system/scripts/erbb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ def setup (args):
print ('Error: Platform %s unsupported' % platform.system ())
sys.exit (1)

if args.with_vscode_support:
setup.install_vscode_support ()

setup.install_python_requirements ()
setup.optimize_kicad_pcb_sch_read ()
setup.check_toolchain ()
Expand Down Expand Up @@ -409,6 +412,11 @@ def parse_args_setup (parent):
help = 'add Xcode extra support such as erbui/erbb syntax coloring'
)

parser.add_argument(
'--with-vscode-support',
action = 'store_true',
help = 'add Visual Studio Code extra support such as erbui/erbb syntax coloring'
)


#-- parse_args_init ----------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions build-system/setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io
import os
from pathlib import Path
import platform
import shutil
import subprocess
Expand Down Expand Up @@ -438,6 +439,28 @@ def install_ideplugin (name):



"""
==============================================================================
Name: install_vscode_support
==============================================================================
"""

def install_vscode_support ():
print ('Adding vscode support...')

path_vscode_extensions = os.path.join (Path.home (), '.vscode', 'extensions')
path_src = os.path.join (PATH_BUILD_SYSTEM, 'setup', 'vscode')
path_dst = os.path.join (path_vscode_extensions, 'eurorack-blocks-vscode')

if os.path.exists (path_vscode_extensions) and os.path.isdir (path_vscode_extensions):
if os.path.exists (path_dst) and os.path.isdir (path_dst):
shutil.rmtree (path_dst)
shutil.copytree (path_src, path_dst)
else:
print (f"\033[33mwarning:\033[0m Can't find vscode extensions folder {path_vscode_extensions}.\nPlease make sure Visual Studio Code is properly installed and run `erbb setup --with-vscode-support` again.")



"""
==============================================================================
Name: install_python_requirements
Expand Down
4 changes: 4 additions & 0 deletions build-system/setup/vscode/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/**
.vscode-test/**
.gitignore
vsc-extension-quickstart.md
12 changes: 12 additions & 0 deletions build-system/setup/vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# eurorack-blocks-vscode

A Visual Studio Code extension for `eurorack-blocks` languages.

Eurorack-blocks allows doing software to Hardware prototyping for Eurorack using C++, Max/Gen~ or Faust. For more informations, please visit the [eurorack-blocks](https://github.com/ohmtech-rdi/eurorack-blocks) repository.

![erbui file screenshot](images/erbui_file_screenshot.png)
![erbb file screenshot](images/erbb_file_screenshot.png)

## Features

- Provides syntax highlighting of `.erbui` and `.erbb` files.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 build-system/setup/vscode/language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
52 changes: 52 additions & 0 deletions build-system/setup/vscode/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "eurorack-blocks-vscode",
"displayName": "eurorack-blocks-vscode",
"description": "Syntax highlighter for eurorack-blocks files",
"version": "0.0.1",
"repository": {
"url": "https://github.com/ohmtech-rdi/eurorack-blocks"
},
"homepage": "https://github.com/ohmtech-rdi/eurorack-blocks/tree/main/build-system/setup/vscode",
"engines": {
"vscode": "^1.79.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [
{
"id": "erbui",
"aliases": [
"erbui"
],
"extensions": [
".erbui"
],
"configuration": "./language-configuration.json"
},
{
"id": "erbb",
"aliases": [
"erbb"
],
"extensions": [
".erbb"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "erbui",
"scopeName": "source.erbui",
"path": "./syntaxes/erbui.tmLanguage.json"
},
{
"language": "erbb",
"scopeName": "source.erbb",
"path": "./syntaxes/erbb.tmLanguage.json"
}
]
}
}
79 changes: 79 additions & 0 deletions build-system/setup/vscode/syntaxes/erbb.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "erbb",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#strings"
},
{
"include": "#variables"
},
{
"include": "#comments"
}
],
"repository": {
"keywords": {
"patterns": [
{
"name": "keyword.control.erbb",
"match": "\\b(module|file|import|define|base|section|resources|sources|data|stream|faust|address|bind|init|use|strict)\\b"
},
{
"name": "keyword.control.erbb",
"match": "\\b(flash|qspi|mono|interleaved|planar)\\b"
},
{
"name": "keyword.type.erbb",
"match": "\\b(AudioSample)\\b"
}
]
},
"strings": {
"name": "string.quoted.double.erbb",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.erbb",
"match": "\\\\."
}
]
},
"variables": {
"patterns": [
{
"match": "[a-zA-Z0-9_]",
"name": "entity.name.variable.erbui"
}
]
},
"comments": {
"patterns": [
{
"begin": "/\\*",
"captures": {
"0": {
"name": "punctuation.definition.comment.erbb"
}
},
"end": "\\*/",
"name": "comment.block.erbb"
},
{
"captures": {
"1": {
"name": "punctuation.definition.comment.erbb"
}
},
"match": "(//).*$\\n?",
"name": "comment.line.double-slash.erbb"
}
]
}
},
"scopeName": "source.erbb"
}
118 changes: 118 additions & 0 deletions build-system/setup/vscode/syntaxes/erbui.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "erbui",
"scopeName": "source.erbui",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#strings"
},
{
"include": "#numbers"
},
{
"include": "#variables"
},
{
"include": "#comments"
}
],
"repository": {
"keywords": {
"patterns": [
{
"name": "keyword.control.erbui",
"match": "\\b(module|board|width|material|header|footer|line|control|label|sticker|image|pin|pins|normalling|mode|positioning|position|rotation|offset|route|faust|address|bind|init|value|property|exclude|extends|alias|file|class|include|pcb|net|type|gpio|pwm|dac)\\b"
},
{
"name": "keyword.control.erbui",
"match": "\\b(style)\\b"
},
{
"name": "keyword.type.erbui",
"match": "\\b(AudioIn|AudioOut|Button|CvIn|CvOut|GateIn|GateOut|LedBi|LedRgb|Led|Pot|Switch|Trim)\\b"
}
]
},
"variables": {
"patterns": [
{
"name": "entity.name.variable.erbui",
"match": "\\b(center|left|top|right|bottom|normalized|bipolar|wire|manual|natural|black|white|aluminum|brushed_aluminum|aluminum_coated)\\b"
},
{
"match": "[a-zA-Z0-9_]",
"name": "entity.name.variable.erbui"
}
]
},
"strings": {
"name": "string.quoted.double.erbui",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.erbui",
"match": "\\\\."
}
]
},
"numbers": {
"patterns": [
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+°cw\\b"
},
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+°ccw\\b"
},
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+°\\b"
},
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+hp\\b"
},
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+mm\\b"
},
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+cm\\b"
},
{
"name": "constant.numeric.erbui",
"match": "\\b[0-9.]+\\b"
}
]
},
"comments": {
"patterns": [
{
"begin": "/\\*",
"captures": {
"0": {
"name": "punctuation.definition.comment.erbui"
}
},
"end": "\\*/",
"name": "comment.block.erbui"
},
{
"captures": {
"1": {
"name": "punctuation.definition.comment.erbui"
}
},
"match": "(//).*$\\n?",
"name": "comment.line.double-slash.erbui"
}
]
}
}
}

0 comments on commit ded0e9c

Please sign in to comment.