vscode new language configuration not changing syntax colors - json

I'm trying to create a new language for syntax highighting in Visual Studio Code for the CPU12 assembly language. When I use the new language in a new .asm file, the editor knows that the comment character is (it adds a semicolon to a line when I type ctrl-k ctrl-c), but the text is white instead of the default comment color green. Do I need to specify to use the default vscode theme? If so, where?
package.json
{
"name": "cpu12",
"displayName": "cpu12",
"description": "cpu12",
"version": "0.0.1",
"publisher": "https://github.com/me",
"engines": {
"vscode": "^1.15.0"
},
"categories": [
"Languages"
],
"contributes": {
"languages": [{
"id": "cpu12",
"aliases": ["CPU12", "cpu12"],
"extensions": [".asm",".inc"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "cpu12",
"scopeName": "source.cpu12",
"path": "./syntaxes/cpu12.tmLanguage.json"
}]
}
}
language-configuration.json
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": ";"
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
(My ./syntaxes/cpu12.tmLanguage.json is empty.)

The problem was actually because ./syntaxes/cpu12.tmLanguage.json was empty. You need to specify in the .json file how to color line comments:
./syntaxes/cpu12.tmLanguage.json
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "cpu12",
"scopeName": "source.cpu12",
"patterns": [
{
"comment": "Line Comments -- Asterisk only works at beginning of line",
"match": "((;|^\\*).*$)",
"captures": {
"1" :{
"name": "comment.line.cpu12"
}
}
}
]
}

Related

Need help editing "Preferences.sublime-settings - User"

Ok... I'm very new, so please be nice :)
I'm trying to change the cursor, but I don't know how to add the "cursor code" to the "theme code" (monokai pro). The "theme code" is below "cursor code", how do I use both successfully? All I want to do is change the cursor.
How do I add this code (cursor code)
{
"caret_extra_width": 5,
"caret_style": "solid",
"wide_caret": true
}
To this code (theme code)
{
"author": "Chris Kempson",
"color_scheme": "Packages/Theme - Monokai Pro/Monokai Pro.sublime-color-scheme",
"globals":
{
"background": "var(blue5)",
"caret": "var(white)",
"foreground": "var(white)",
"invisibles": "var(blue7)",
"line_highlight": "var(blue)",
"selection": "var(blue2)"
},
"ignored_packages":
[
"Vintage"
],
"name": "Tomorrow Night - Blue",
"rules":
[
{
"foreground": "var(grey)",
"name": "Comment",
"scope": "comment, string.quoted.double.block.python"
},
{
"foreground": "var(white)",
"name": "Foreground, Operator",
"scope": "keyword.operator.class, keyword.operator, constant.other, source.php.embedded.line"
},
{
"foreground": "var(red3)",
"name": "Variable, String Link, Regular Expression, Tag Name",
"scope": "variable, support.other.variable, string.other.link, string.regexp, entity.name.tag, entity.other.attribute-name, meta.tag, declaration.tag"
},
{
"foreground": "var(orange)",
"name": "Number, Constant, Function Argument, Tag Attribute, Embedded",
"scope": "constant.numeric, constant.language, support.constant, constant.character, variable.parameter, punctuation.section.embedded, keyword.other.unit"
},
{
"foreground": "var(orange2)",
"name": "Class, Support",
"scope": "entity.name.class, entity.name.type.class, support.type, support.class"
},
{
"foreground": "var(green)",
"name": "String, Symbols, Inherited Class, Markup Heading",
"scope": "string, constant.other.symbol, entity.other.inherited-class, markup.heading"
},
{
"foreground": "var(blue6)",
"name": "Operator, Misc",
"scope": "keyword.operator, constant.other.color"
},
{
"foreground": "var(white3)",
"name": "Function, Special Method, Block Level",
"scope": "entity.name.function, meta.function-call, support.function, keyword.other.special-method, meta.block-level"
},
{
"foreground": "var(white2)",
"name": "Keyword, Storage",
"scope": "keyword, storage, storage.type, entity.name.tag.css"
},
{
"background": "var(red2)",
"foreground": "var(white)",
"name": "Invalid",
"scope": "invalid"
},
{
"background": "var(white4)",
"foreground": "var(white)",
"name": "Separator",
"scope": "meta.separator"
},
{
"background": "var(white2)",
"foreground": "var(white)",
"name": "Deprecated",
"scope": "invalid.deprecated"
},
{
"foreground": "var(white)",
"name": "Diff foreground",
"scope": "markup.inserted.diff, markup.deleted.diff, meta.diff.header.to-file, meta.diff.header.from-file"
},
{
"foreground": "var(yellow)",
"name": "Diff insertion",
"scope": "markup.inserted.diff, meta.diff.header.to-file"
},
{
"foreground": "var(red)",
"name": "Diff deletion",
"scope": "markup.deleted.diff, meta.diff.header.from-file"
},
{
"background": "var(blue4)",
"foreground": "var(white)",
"name": "Diff header",
"scope": "meta.diff.header.from-file, meta.diff.header.to-file"
},
{
"font_style": "italic",
"foreground": "var(blue3)",
"name": "Diff range",
"scope": "meta.diff.range"
},
{
"foreground": "var(red4)",
"name": "diff.deleted",
"scope": "markup.deleted"
},
{
"foreground": "var(yellow2)",
"name": "diff.inserted",
"scope": "markup.inserted"
},
{
"foreground": "var(purple)",
"name": "diff.changed",
"scope": "markup.changed"
}
],
"theme": "Agila.sublime-theme",
"variables":
{
"blue": "#00346e",
"blue2": "#003f8e",
"blue3": "#3e999f",
"blue4": "#4271ae",
"blue5": "#002451",
"blue6": "#99ffff",
"blue7": "#404f7d",
"green": "#d1f1a9",
"grey": "#999999",
"orange": "#ffc58f",
"orange2": "#ffeead",
"purple": "#967efb",
"red": "#c82829",
"red2": "#f99da5",
"red3": "#ff9da4",
"red4": "#f92672",
"white": "#ffffff",
"white2": "#ebbbff",
"white3": "#bbdaff",
"white4": "#bbdafe",
"yellow": "#718c00",
"yellow2": "#a6e22e"
}
}
Without getting this error message:
Error trying to parse settings: Unexpected trailing characters in
Packages/User/Preferences.sublime-settings
Thank you guys!
What you are calling your "cursor code" is actually some preferences. They should be added to your user preferences (available via Preferences → Settings on the right side). Don't erase what's already there, just follow the rules of JSON - start with an opening curly brace { on one line, then have one preference per line with a comma , at the end of each line, then close with a curly brace }. You can have as many preferences set as you want, don't limit it to just those three. Look at the default preferences on the left for a list of every single one that's available. Don't worry if you don't understand what they all mean - you can customize just about every single thing about Sublime!
As far as the color scheme, which is kind of what your lower piece of code is - the easiest thing to do is to install Monokai Pro from Package Control and ignore that code completely - it's corrupted. If you haven't installed Package Control yet, install it by selecting Tools → Install Package Control…. Once that's done, hit CtrlShiftP on Windows/Linux, ⌘ShiftP on macOS, to open the Command Palette. Type in pci (short for Package Control: Install Package), hit Enter, type in monpro, select Theme - Monokai Pro, and hit Enter again. You may see a message on the status bar (down at the very bottom of the window) saying it's installing.
Once it installs, select Preferences → Color Scheme…, scroll through the list of options, click on Monokai Pro, hit Enter, and you should be good to go. I know it looks a little complicated, but in reality it's not. Once Package Control is installed, you don't have to install it again (in fact - you can't install it again). You should also learn through this exercise that all Sublime modal menus have fuzzy search, so you can usually just type a couple of letters and the option you want will pop right up.

how do i get rid of the json errors : line 2-4 Comments are not permitted in JSON. line 62 char 2 end of file expected

i am working on learning more about json code and how to get rid of the json errors and i am just working from the script i would like to make a better script. i did do everything i could think of to get rid of the errors without changing the language in visual studios, what is your solution to get rid of the errors?
here are the error message in visual studio:
line 2-4 Comments are not permitted in JSON.
line 62 char 2 end of file expected
the following json script is used to make the c++ debugger run and is used to enable visual studio to identifiy c++ errors. i am just tweaking it.
{
line 2 // Use IntelliSense to learn about possible attributes.
line 3 // Hover to view descriptions of existing attributes.
line 4 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"customLaunchSetupCommands": [
{ "text": "target-run", "description": "run target", "ignoreFailures": false }
],
"launchCompleteCommand": "exec-run",
"windows :gdb"
:"C:\\MinGw\\bin\\gdb.exe"
}
]
,"name": "(gdb) Bash on Windows Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"pipeTransport": {
"debuggerPath": "/usr/bin/gdb",
"pipeProgram": "${env:windir}\\system32\\bash.exe",
"pipeArgs": ["-c"],
"pipeCwd": ""
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
[enter image description here][1] ],"customLaunchSetupCommands": [
{ "text": "target-run", "description": "run target", "ignoreFailures": false }
],
"launchCompleteCommand": "exec-run",
"windows" : "gdb,"
,"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
line 62 }[
]
to get rid of the line 2-4 Comments are not permitted in JSON. remove a backslash on 2 of those lines and a colon. remove the brackets at line 62.

Specify shared/'common' values for configurations in CppProperties.json or CMakeSettings.json

When using the "Open Folder" functionality of Visual Studio, the IDE searches for project settings and configurations in a special json file. For CPP projects, this could be CppProperties.json. For CMake projects, this could be CMakeSettings.json.
This json file contains a collection of one or more "configurations," such as "Debug" or "Release". I will use a recent CMake project as an example:
"configurations": [
{
"name": "ARM-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"gcc-arm"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"intelliSenseMode": "linux-gcc-arm",
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "${workspaceRoot}/cmake/arm-none-eabi-toolchain.cmake"
}
]
},
{
"name": "ARM-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"gcc-arm"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"intelliSenseMode": "linux-gcc-arm",
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "${workspaceRoot}/cmake/arm-none-eabi-toolchain.cmake"
}
]
}
As you can see, I have two configurations with nearly identical properties.
My question: is it possible to define these common/shared properties once, in such a way as to allow the configurations to inherit them and avoid repeating myself?
The easier way is to define an environment at global level (outside of any configuration), such as:
{
"environments": [
{
"namespace" : "env",
"varName": "varValue"
}
],
Then you can reuse that wherever you need to, e.g.:
"cmakeCommandArgs": "${env.varName}",
You can also have multiple environments, and reuse them, like this:
{
"environments": [
{
"environment": "env1",
"namespace": "env",
"varName": "varValueEnv1"
},
{
"environment": "env2",
"namespace": "env",
"varName": "varValueEnv2"
}
],
"configurations": [
{
"name": "x64-Release",
"inheritEnvironments": [
"msvc_x64_x64", "env2"
],
"cmakeCommandArgs": "${env.varName}",
.....
}
]
the 'x64-Release' will inherit the variables's value in the environment called "env2" (namespace 'env')

Visual Studio Code: Comments not being detected while trying to add support for a new language/filetype

So I am working on a research project that involves using a very specific piece of software that uses its own filetype; XPPAUT using .ode files. To prevent me and my team of not-neuroscientists from ripping our hair out trying to work with this, I decided to write a syntax highlighter for these .ode files.
To start I just wanted to be able to recognize and color linecomments, which are delineated with a #, similar to Python, however when I run the development environment, the comments are not highlighted with the color I set my dev workspace to use, or highlighted at all. I'm very new to this, so any help would be appreciated.
Here is my package.json file
{
"name": "ode",
"displayName": "XPP ODE",
"description": "ODE files to be used with XPP/XPPAUT",
"version": "0.0.1",
"publisher": "wjmccann",
"engines": {
"vscode": "^1.22.0"
},
"categories": [
"Languages"
],
"contributes": {
"languages": [{
"id": "xpp",
"aliases": ["XPP ODE", "XPP", "XPPAUT"],
"extensions": [".ode"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "xpp",
"scopeName": "source.xpp",
"path": "./syntaxes/xpp.tmLanguage.json"
}]
}
}
and the corresponding language-configuration.json
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "#",
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
The language-configuration.json file defines text patterns used in a variety of standard features of VS Code such as comment toggling as described here.
Syntax highlighting/colouring is via the grammars contribution point in package.json as described here.
Based on your package.jsonyou will need to create a new file at ./syntaxes/xpp.tmLanguage.json with the following content for your comments to be coloured appropriately. The actual colour used will depend on your current theme.
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "xpp",
"scopeName": "source.xpp",
"patterns": [
{
"include": "#comments"
}
],
"repository": {
"comments": {
"patterns": [{
"name": "comment.line.number-sign.xpp",
"match": "#.*"
}]
}
}
}

Saxon's Error Code format?

I'm using Sublime Text and I just wanted to know where I should look for Saxon's error code format.
For my project, I'm using the following JSON format to describe the build system I'm using:
{
"build_systems":
[
{
"name": "[Kolcraft] Validate Feed",
"file_regex": "",
"working_dir": "${project_path}",
"shell_cmd": "xmllint --noout --schema src/ProductFeed5.6.xsd src/bv-kolcraft.xml",
"selector": "source.xml"
},
{
"name": "[Contours] Validate Feed",
"file_regex": "",
"working_dir": "${project_path}",
"shell_cmd": "xmllint --noout --schema src/ProductFeed5.6.xsd src/bv-contours.xml",
"selector": "source.xml"
},
{
"name": "[Kolcraft] Transform Export",
"file_regex": "",
"env": {
"CLASSPATH": ".;backup/saxon9pe.jar;backup/saxon9-icu.jar;backup/saxon9-sql.jar;backup/saxon9pe-test.jar"
},
"working_dir": "${project_path}",
"shell_cmd": "java net.sf.saxon.Transform -o:src/bv-contours.xml -s:src/CONTOURS.xml -xsl:src/mrc2bv.xsl -xsltversion:2.0 -ext:on feedName=kolcraft -traceout:#out",
"selector": "source.xml"
},
{
"name": "[Contours] Transform Export",
"file_regex": "",
"env": {
"CLASSPATH": ".;backup/saxon9pe.jar;backup/saxon9-icu.jar;backup/saxon9-sql.jar;backup/saxon9pe-test.jar"
},
"working_dir": "${project_path}",
"shell_cmd": "java net.sf.saxon.Transform -o:src/bv-kolcraft.xml -s:src/KOLCRAFT.xml -xsl:src/mrc2bv.xsl -xsltversion:2.0 -ext:on feedName=contoursbaby -traceout:#out",
"selector": "source.xml"
},
],
"folders":
[
{
"path": ".",
"folder_exclude_patterns": [".*", "backup", "schema"]
},
{
"path": "schema",
"name": "Schema"
}
]
}
What Sublime Text does to capture error output is use the file_regex field. It uses a regular expression rather than rely on any external listener program, or watch the sys.stderr stream from it's embedded Python interpreter.
I just want to be able to use the right regular expression for the build system, is all. Can anyone help?