VSCode debugger having issues with character encoding - visual-studio-code

This question was asked before here but there is no answers on this questions.
When trying to debug char or string type, the debugger prints <error reading variable> or Converting character sets: Invalid argument respectively instead of its value.
This problem can be fixed by running -exec set charset UTF-8 from the debug console while debugging but it is only a temporary fix, and has to be run every time on debugger startup manually.
Is there a way to permanently fix this issue? (I'd prefer not to change any system settings)

In the Launch.json file, adding set charset UTF-8 to the setupCommands fixed it.
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set charset UTF-8"
}
]

Related

How to fix Visual Studio Code distorting characters on Windows?

I have problems with Swedish national characters when using Rust in Visual Studio Code in Windows 11. It can be shown with the following program:
fn main() {
let abc = " ååå
ööö
äää";
println!("<---{}--->", abc);
}
When the program is run from the command line using cargo run, the output is as follows:
<--- ååå
ööö
äää--->
Strangely, spaces are added at the beginning of lines 2 and 3. However, when the program is run in Visual Studio Code, the Swedish characters get distorted.
<--- ååå
├╢├╢├╢
äää--->
How can I solve it? I work with text processing and this is a major problem.
EDIT: Since the problem doesn't appear on many systems, I add the technical data: Windows 11 Pro Version 10.0.22621 Build 22621;
Visual Studio Code Version: 1.73.1 (user setup) Date: 2022-11-09 Chromium: 102.0.5005.167 Node.js: 16.14.2 Sandboxed: No.
- This answer is Windows specific. -
INFO: This answer describes you how can change your VSCode settings to force UTF-8 in your console. An alternative to this answer would be to force UTF-8 system-wide, as described here: Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)
It seems that sometimes the Windows shell doesn't use the correct UTF-8 code page.
You can tell VSCode to force a codepage in its shell using the following settings.
Open the Settings page (Shortkey: Ctrl+,)
Click on the button on the top right whose mouse-over text reads "Open Settings (JSON)"
Add the following lines:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"/c",
"chcp.com 65001"
]
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"chcp 65001"
],
"icon": "terminal-cmd"
},
},
This will force the UTF-8 code page.
If it worked, opening a new shell should display Active code page: 65001.
Source: https://github.com/microsoft/vscode/issues/19837
Previous, deprecated settings:
If your shell is "CMD":
"terminal.integrated.shellArgs.windows": ["/K", "chcp 65001"],
If your shell is "Powershell":
"terminal.integrated.shellArgs.windows": ["-NoExit", "/c", "chcp.com 65001"],

How to fix vscode GnuCOBOL setup "configuration error: default.conf: No such file or directory"

we are using cobol now, but this config error keeps on appearing and I do not know how to fix this thing. Any help would really mean alot. (Just a beginner and trying to learn vscode)
Late, but perhaps worth it. Currently there is a cobenv.bat or .sh (if you are on linux). The whole path to the file may differ for me is this:
C:\msys64\mingw64\bin\cobenv.cmd
You'll notice that if you execute the file and run the compiler everything works fine, but once you close that bash the error shows up again.
That's because the scope of those variables was just that session. You may execute it every time you run the compiler or you can make those variables to persist on your system. In my case I did the later, modifying cobenv.cmd
But not those lines with the variable PATH.
So this lines, i.e., whenever we encounter this same three variables. For instance, after a certain if in that file we encounter:
setx "COB_LIBRARY_PATH" "%MINGW_ROOT_PATH%lib\gnucobol%COB_LIBRARY_PATH%"
setx "COB_COPY_DIR" "%MINGW_ROOT_PATH%share\gnucobol\copy"
setx "COB_CONFIG_DIR" "%MINGW_ROOT_PATH%share\gnucobol\config"
Default value: set.
New value: setx.
Delete the = to comply with the correct syntax. Check the compiler with different new session.
This message is only presented in vscode's Terminal after you've entered a command there, it is actually not related to vscode.
The "common" way with vscode would be to create a vscode task for the compilation and configure a problem matcher, too, so vscode is able to parse the messages. For details see vscode docs "Integrate with External Tools via Tasks".
As the message is coming from the GnuCOBOL compiler it may be reasonable to check in its discussion board, which also includes a note how to use your setup of vscode with GnuCOBOL MinGW package, this would be your starting point, assuming D:\COBOL is the place where you have your sources (and this is the alos the workspaceFolder as in your screenshot), D:\COBOL\copy where your copybook reside and D:\GnuCOBOL where the MinGW package is:
{
"version": "2.0.0",
"tasks": [
{
"label": "GnuCOBOL - cobc (compile single file)",
"type": "shell",
"command": "cobc",
"args": [
"-I${workspaceFolder}\\copy",
"${file}"
],
"problemMatcher": "$gnucobol3-cobc",
"options": {
"env": {
"COB_CFLAGS": "-I\"D:\\GnuCOBOL\\include\"",
"COB_CONFIG_DIR": "D:\\GnuCOBOL\\config",
"COB_COPY_DIR": "D:\\GnuCOBOL\\copy",
"COB_LDFLAGS": "-L\"D:\\GnuCOBOL\\lib\"",
"COB_LIBRARY_PATH": "D:\\GnuCOBOL\\extras",
"PATH": "D:\\GnuCOBOL\\bin:${env:PATH}"
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Instead of directly calling cobc you could also call cobc.bat or similar, then create it with all your default options set there (or, if you use the official mingw packages, just call the set_env.cmd) then call the compiler.
Concerning "how to fix that message" - make sure you have the "config" directory of GnuCOBOL and have COB_CONFIG_DIR set to it either in the task definition or outside of vscode (for example by starting vscode from the "Developer prompt for GnuCOBOL MinGW" (which is the set_env.cmd distributed with it).

LaTeX Workshop does'nt work well (Recipe terminated with error.)

Problem
I fail to build the LaTeX document on the VScode with LaTeX Workshop.
More preciously, ctrl + S can save the document but can't build the pdf. VScode warns "Recipe terminated with error".
The thing is that I was able to build the LaTeX documents earlier, but yesterday it abruptly didn't work well. Although I didn't change any option about LaTeX, I changed some settings about Python. For example, I uninstalled Anaconda and tried to create virtual environment of python with pipenv. However, I don't think those change are related to this problem...
settings.json
settings.json is as following.
{
"editor.suggest.snippetsPreventQuickSuggestions": false,
// ---------- LaTeX Workshop ----------
"latex-workshop.intellisense.package.enabled": true,
"latex-workshop.message.log.show": true,
"latex-workshop.message.badbox.show": true,
"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.recipes": [{
"name": "ptex2pdf",
"tools": [
"ptex2pdf"
]
}],
"latex-workshop.latex.tools": [{
"name": "ptex2pdf",
"command": "ptex2pdf",
"args": [
"-l",
"-ot",
"-kanji=utf8 -synctex=1 -interaction=nonstopmode",
"%DOC%"
]
}],
"latex-workshop.message.latexlog.exclude":["(Font shape `(JY1|JT1|JY2|JT2)(/.*)(sl|it|sc)'.*|Some font shapes were not available.*)"]
}
Additional information
Since I hadn't used Workspace of VScode yet, but yesterday I started to use that. Since I thought it
may be the reason of the problem, now I stop using the worspace, but the situation doesn't change.
Furthermore, if I run on the cmd on VScode,
platex hoge.tex
dvipdfmx hoge.dvi
the pdf was outputted successfully.
environment
Windows10 Home
VScode 1.49.0
LaTeX Workshop 8.13.2

Enable xelatex in Latex Workshops for Visual Studio Code

I have a template, which defines all the typesetting recommendations for thesis, but it uses xelatex for compilation. I want to continue using VS Code with Latex Workshops, question is how to change compiler to xelatex from pdflatex. The last one cause next error log:
C:\Users\User\AppData\Local\Programs\MiKTeX 2.9\tex/latex/fontspec\fontspec.sty:45: Fatal Package fontspec Error: The
fontspec package requires either XeTeX or
(fontspec) LuaTeX.
(fontspec)
(fontspec) You must change your typesetting engine to,
(fontspec) e.g., "xelatex" or "lualatex"instead of
(fontspec) "latex" or "pdflatex".
The simplest solution found in issues here, but in more common formulation:
Copying the content, simply go to Preferences → Extensions → LaTeX (meaning LaTeX is LaTeX workshops), find gear-wheel button with name Manage, then find in the list link to settings.json under any tag, open and type next:
"latex-workshop.latex.tools": [{
"name": "latexmk",
"command": "latexmk",
"args": [
"-xelatex",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}],
Reloading the VSCode may be needed.
Also setting.json file could be found in C:\Users\*\AppData\Roaming\Code\User\settings.json.
Use magic comments
add the following line to the beginning of your document.
% !TEX program = xelatex
To enable magic comments, change the setting forceRecipeUsage to false.
I kept getting errors with the other solutions, apparently because I was using backend=biber in my latex code. The following configuration assumes a current MiKTeX setup (including biber) and fixes those problems (also, this does not rely on latexmk). The config uses some inspiration from that of TeXworks.
Inside latex-workshop.latex.tools
{
"name": "xelatex",
"command": "xetex",
"args": [
"-undump=xelatex",
"%DOC%.tex"
],
"env": {}
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOC%"
],
"env": {}
}
Then inside latex-workshop.latex.recipes add the recipe:
{
"name": "xelatex ➞ biber ➞ xelatex x 2x",
"tools": [
"xelatex",
"biber",
"xelatex",
"xelatex"
]
}
Happy texing!

Correct display Cyrillic symbols in SublimeREPL PowerShell

Summary
I can not to make correct display Cyrillic symbols in SublimeREPL PowerShell.
Expected behavior
In Windows PowerShell I have not this problem.
Actual behavior
Cyrillic symbols always not displayed for me. I see mojibake instead it.
Steps to reproduce
The problem is reproduced for me in a version of Sublime Text without plugins and user settings.
Preferences → Key Bindings → I change Default (Windows).sublime-keymap - User:
[
{
"keys": ["super+alt+p"],
"command": "repl_open",
"args": {
"type": "powershell",
"encoding": "utf-8",
"cmd": ["powershell", "-"],
"cwd": "$file_path",
"external_id": "powershell"
}
}
]
When test.md in my E:\Киролайна folder is opened, I press Super+Alt+P → I get actual behavior.
Not helped
I saw in my PowerShell settings. I have 866 (OEM - русская) encoding.
I change encoding: I run in PowerShell command chcp 65001:
PS E:\Киролайна> chcp 65001
Active code page: 65001
PS E:\Киролайна> chcp
Active code page: 65001
PS E:\Киролайна>
But problem is remained for me.
I try to change encoding in my keymap file:
"encoding": "$win_cmd_encoding"
"encoding": "cp866"
"encoding": "cp1251"
When I press Super+Alt+P in open file, I get error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 9: invalid start byte
error: UnicodeDecodeError('utf-8', b'C:\Users\\x8a\xae\xe2\AppData\Roaming', 9, 10, 'invalid start byte')
Correct path is C:\Users\Кот\AppData\Roaming, path contain Cyrillic symbols Кот.
Environment
Operating system and version:
Russian Windows 32-bit 10.0.14393
Sublime Text:
Build 3126