Why is syntax highlighting not showing for my custom extension in VS Code? - visual-studio-code

I am trying to create a custom language-extension for VS Code. I was mostly following the instructions given here and here.
When I run the extension in the Extension Development Host by hitting F5, everything works fine. As soon as I try to install my extension and use it in VS Code, it does no longer.
From here I gathered that I have three options of installing my extension
bundle my extension to a vsix with vsce and install it from within VS Code
install the vsix package from command line with code --install-extension myExt.vsix
copy the content to a folder in %userprofile%\.vscode\extensions
All three options give the same result: syntax highlighting does not work for keywords, etc. but it does work for comments. Using the Scope Inspector I can see that all the tokens are correctly deteced and categorized, so the extension seems to be basically working, but code is not highlighted (again, except for comments, weirdly).
The only clue I get when I install via command line is
Installing extensions...
(node:34352) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Extension 'vscode-knitout.vsix' was successfully installed.
but I doubt that this has got anything to do with the problem.
This here is my package.json file:
{
"name": "vscode-myLanguage",
"displayName": "myLanguage",
"description": "myLanguage language extension for VS Code",
"version": "0.0.1",
"publisher": "me",
"author": {
"name": "name"
},
"icon": "images/icon.png",
"galleryBanner": {
"color": "#C80000",
"theme": "dark"
},
"engines": {
"vscode": "^1.53.0"
},
"license": "SEE LICENSE IN LICENSE.txt",
"repository": {
"type": "git",
"url": "https://some.git.url"
},
"homepage": "https://our.website",
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "myLanguage",
"aliases": ["myLanguage", "myLanguage"],
"extensions": [".m",".myLanguage"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "myLanguage",
"scopeName": "source.myLanguage",
"path": "./syntaxes/myLanguage.tmLanguage.json"
}],
"themes": [
{
"label": "myLanguage-dark",
"uiTheme": "vs-dark",
"path": "./themes/myLanguage-vs-dark-color-theme.json"
}
]
}
}
When I run via Extension Development Host, the Scope Inspector correctly recognizes the language and textmate scopes and respective theme rule for 'foreground'. When I run VS Code with the extension installed/copied, the Scope Inspector says "No theme selector" for 'foreground', but everything else (scope, language) looks correct.
What is the problem here? Is there a very simple example somewhere for a reference?

Related

Why is build tasks not showing up in VSCode?

Hi I'm doing Unreal 5 Udemy Course and in video it is this image
But when I try it looks like this
I am changed to MSVC version v14.30 - 17.0 so that my UE5 live coding works but i don't think that is why build tools are not showing. But not sure how it would be fixed. What can it be do you know?
So the problem is that you haven't build anything, as I understood.
You need to make something like that in your dir
Workplace look with correct tasks.json
{PathToYourUeProjDir}/.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "UnrealGame Mac Development Build",
"group": "build",
"command": "/Users/Shared/Epic Games/UE_5.0/Engine/Build/BatchFiles/Mac/Build.sh",
"args": [
"UnrealGame",
"Mac",
"Development",
"-waitmutex",
"-architecture=arm64"
],
"problemMatcher": "$msCompile",
"dependsOn": [
"UnrealBuildTool Mac Development Build"
],
"type": "shell",
"options": {
"cwd": "${workspaceFolder}"
}
},
]
}
You may need to correct "command" path, it is path to your ue5.
And you may also need to correct options.cwd, here I'm not sure
Then you just build with cmd+shift+B.
Keep in mind that I installed the xcode version 13 (it is still recommended by UE) from apple dev. And in xcode-preferences-locations I set up command line tools to xcode13. I'm not sure is it crucial, but that is the way it works for me now.

How to add Lua libraries into a project and use "require" in Visual Studio Code

I am quite new to Lua and couldn't information as to how to add Lua libraries into a project and use "require" in Visual Studio Code
You can define your package.path and package.cpath in your launch.json file for the project.
your configuration would look something like this:
"configurations": [
{
"type": "lua",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/test.lua",
"path": "${workspaceFolder}/?.lua;C:\\lua\\?.lua"
}
]
how these variable work with require is explained in
Programming in Lua: 8.1 – The require Function

How to set up a Zephyr Project App in VSC?

I am trying to use VSC to develop and debug embedded C applications with Zephyr OS. Is this possible? Are there instructions to set this up? Is there a zephyr setup extension? The Zephyr documentation discusses how to debug apps on eclipse, and there is an eclipse/zephyr plug-in, but I'd prefer to use VSC if possible.
Since Zephyr utilizes CMake, I thought I follow the VSC CMake project tutorial. When it asks to select a kit, there was nothing appropriate for zephyr, so I left it with no active kit selected. With this setting, I am actually able to get a successful build for the blinky example but cannot debug the project. The error I get is:
ERROR: Unable to start debugging. Unexpected GDB output from command
"-exec-run". Don't know how to run. Try "help target". The program
'/home/mustafa/Code/Sycamore/hello_world/build/zephyr/zephyr.elf' has
exited with code 42 (0x0000002a).
If anyone has any input on how to address this error or instructions on setting up a zephyr project in VSC, that would be great. Thx!
Only few steps enough:
Add necessary folders to workspace like:
"folders": [
{
"path": ".",
"name": "app"
},
{
"path": "..\\zephyr",
"name": "zephyr"
},
{
"path": "..\\mcuboot"
},
{
"path": "..\\modules\\hal\\stm32"
}
]
Install Cortex-Debug extension
Setup debug session in file .vscode/launch.json:
"configurations": [
{
"name": "App",
"cwd": "${workspaceRoot}",
"executable": "./app/build/zephyr/zephyr.elf",
"request": "attach",
"type": "cortex-debug",
"serverpath": "C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe",
"servertype": "jlink",
"device": "stm32f412RE",
"interface": "swd",
"svdFile": "./STM32F412.svd"
},
{
"name": "Bootloader",
"cwd": "${workspaceRoot}",
"executable": "./boot/build/zephyr/boot.elf",
"request": "launch",
"type": "cortex-debug",
"serverpath": "C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServerCL.exe",
"servertype": "jlink",
"device": "stm32f412RE",
"interface": "swd",
"runToMain": true,
"svdFile": "./STM32F412.svd"
}

Cannot update Azure Devops (VSTS) extension

In the Visual Studio Marketplace (https://marketplace.visualstudio.com) I found an extension (version 1) that I now use in my Azure Devops build pipeline. I contacted the author who made a small improvement and the new version of the extension was pushed yesterday. In the VS MarketPlace I also see that v2 has become available. However, when I go to my build pipeline I can still only select version 1.
I've contacted my organization's admin to ensure that the latest version is installed. We have even tried to remove the extension for the organization (at which point that was reflected in my build definition) and re-install it, but still I can only select version 1.
Any ideas why I cannot access the latest version of the extension?
In my case, the problem was not updating the task version in task.json file. Updating the extension's version (in the manifest file) is not enough. If the task version is not changed, Azure DevOps will not update the task itself (despite correctly updating the extension on the "Extensions" page).
Did the extension bundle multiple versions of tasks? Generally, we include one version of a task in your extension. Now it is also possible to include multiple versions in one extension, it is helpful if you want to roll out future versions of your extension without interrupting service of users running older versions. You can see the multiple version layout. You can only select version 1, that means the extension include only one version task, even you updated the version number in the task schema. In other word, the version you can select is not the version of the task itself, it means in this extension includes how many different version task.
Please see following example extension manifest which includes multiple version task.
{
"manifestVersion": 1,
"id": "build-release-extension-task",
"name": "Build and Release Extension Tools",
"version": "0.1.0",
"publisher": "{your publisher id}",
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"description": "Tools for building/releasing with Fabrikam. Includes one build/release task.",
"categories": [
"Azure Pipelines"
],
"icons": {
"default": "images/ic_extension.png"
},
"files": [
{
"path": "buildAndReleaseExtensionTaskV1"
},
{
"path": "buildAndReleaseExtensionTaskV2"
}
],
"contributions": [
{
"id": "custom-build-release-task-v1",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "buildAndReleaseExtensionTaskV1"
}
},
{
"id": "custom-build-release-task-v2",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "buildAndReleaseExtensionTaskV2"
}
}
]
}

Configure Visual Studio Code to have a default Build Task based on file extension

I would like to know if there is a way to define a default Build Task for VSCode depending on file extension.
When working in some folder of Python code, I define the following Build Task:
{
"version": "0.1.0",
"command": "python",
"isShellCommand": true,
"showOutput": "always",
"args": ["${file}"]
}
Then if next time I go to another Python folder, I have to redefine it again.
Is it possible to configure VSCode in such a way that if it detects the current file as a Python script, then it will automatically define the above Build Task?
Thank you in advance for your help!
Update for latest vscode
The following will create a default "build" script, so you can use the keyboard shortcut to build your project. (Below for a javascript project, but shows general outline for other languages/projects.)
(1) Assuming you have a script named "build.js" at the root of your project.
(2) Create a file named "tasks.json" in root of project (workspace) with the following contents:
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "mybuildscript", // use same name as in package.json
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
(3) In your package.json, add "scripts" as:
// package.json
{
"name": "my",
"version": "1.0.0",
"description": "",
"scripts": {
"mybuildscript": "node ./build.js"
},
"dependencies": {
"myfs": "^1.0.22"
}
}
I created a rudimentary vscode extension that does all this for you:
https://marketplace.visualstudio.com/items?itemName=gieson.make-build-task
The extension isn't perfect (doesn't cover all the possible ways a project/workspace can be configured), but it's a good starting point.
Here's the repo:
https://github.com/bobtherobot/make-build-task
This is possible, but it requires writing an extension (unless somebody has already written one with a tasks provider for Python). Since 1.14.0, there's a new API which allows extensions to dynamically provide tasks. Check out the Task Provider Example.
Alternatiely, the Code Runner extension probably does the trick in this case as well. It doesn't use the Tasks system though.