โŒ

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

VSCode extension api - How can I get the files list importing the current active file?

Say there is an active file. If I run the command, I wish all the files that are importing the currently active file are shown on the console.

The active file is not always being imported by its absolute path, but can be a relative path.

For example

// hello.js
export const hello = () => 'world'
// importing-file-{n}.js
import {hello} from '/my/absolute/path';
// or
import {hello} from '../hello.js';
// or (and so on)
import {hello} from '../../hello.js';

The first step I want to achieve is when I run the command, I wish that all the files importing hello.js are printed.

importing-file-1.js
importing-file-2.js
...

How can I do that?

VSCode, There is no "\n" for the mouse over the function

IN VSCode, I used the Doxygen Generator Documentation plug-in to generate the following comments in a functional method. enter image description here

But when I hovered over the function, there was no newline in the function tip about brief enter image description here

This makes me very uncomfortable.This makes me very uncomfortable.

In addition,I'm not sure if Breif is the problem

enter image description here

enter image description here

enter image description here

enter image description here

Hope how to correct this phenomenon

ADB returned null value when connect to device over wifi vscode

I want to connect to the phone via wifi and debug my code. Until a few days ago, it was connected and I was debugging without problems. But recently it encounters the ADB returned null value error. The connection steps are as follows using ADB Interface for VSCode extension:

  1. ctrl + shift + p and select ADB: Connect to device ip like below: 1

  2. Enable Wireless debugging on phone and type given ip address and press enter: 2

  3. Then type the given port and press enter: 3

after few moments, it supposed to show this massage: Connected to <ip>:<port>, but it shows this message and does not connect to the phone:

4

I also tried another extension called Android ADB WLAN, but the result was the same. what is the problem? how can i solve this?

VsCode WebView update cause cursor to blink

I have custom WebView extension for VS Code that is updated whenever some internal value changes and unfortunately cursor icon 'blinks' whenever WebView is updated and cursor is located in editable document. Is there anything i can do to prevent that from happening?[Gif of blinking cursor here] (https://i.stack.imgur.com/Rp28R.gif)

My code looks like this

class LiveVariableViewProvider implements vscode.WebviewViewProvider {
... 
public updateWebview()
{
    const val : string = getHtmlForWebview();
    if (val!=this._view.webview.html)
    {
        this._view.webview.html = val; //causes cursor to 'blink'
    }
}
}

Limit the installation of extensions

I work in an IT department, and we allow the use of vscode. However, certain extensions do not suit us within the framework of our security policy. We would like to prevent users from installing all available extensions, and only allow some that we have validated. I tried adding in the "settings.json" file the parameter "extensions.allowMarketplace": false, but it doesn't work. Do you know another way?

VS Code extension - Webview view is not initialized properly

I am writing an VSCode extension and when I am triggering the "Hello" command - it seems that the webview view in not initialized properly, the the post messages are not sent and the webview view panel is not shown.

MyProvider:

import * as vscode from "vscode";

function getNonce() {
  let text = "";
  const possible =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  for (let i = 0; i < 32; i++) {
    text += possible.charAt(Math.floor(Math.random() * possible.length));
  }
  return text;
}

const MY_COMMAND = "extension.hello";
export class MyProvider implements vscode.WebviewViewProvider {
  public static readonly viewType = MY_COMMAND;

  private _view?: vscode.WebviewView;

  constructor(private readonly _extensionUri: vscode.Uri) {}

  public postMessageToWebview(message: any) {
    console.log("$#@$@#message", message, this._view?.webview);
  }

  public resolveWebviewView(
    webviewView: vscode.WebviewView,
    context: vscode.WebviewViewResolveContext,
    _token: vscode.CancellationToken
  ) {
    this._view = webviewView; // needed so we can use it in postMessageToWebview later

    webviewView.webview.options = {
      // Allow scripts in the webview
      enableScripts: true,
      localResourceRoots: [this._extensionUri],
    };

    webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);

    webviewView.webview.onDidReceiveMessage((data) => {
      console.log("message received");
      switch (data.type) {
        // other message types ...
        case "greeting": {
          console.log("HELLO!!");
          break;
        }
      }
    });
  }

  private _getHtmlForWebview(webview: vscode.Webview) {
    const styleUri = webview.asWebviewUri(
      vscode.Uri.joinPath(this._extensionUri, "src", "media", "style.css")
    );


    const actions = getActions();
    const nonce = getNonce();

    return `<!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <!--
                    Use a content security policy to only allow loading images from https or from our extension directory,
                    and only allow scripts that have a specific nonce.
        -->
        <meta http-equiv="Content-Security-Policy" content="img-src https: data:; style-src 'unsafe-inline' ${webview.cspSource}; script-src 'nonce-${nonce}';">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <link href="${styleUri}" rel="stylesheet">
        <script nonce="${nonce}">
            const tsvscode = acquireVsCodeApi();
        </script>
            </head>
      <body>
      The content goes here
            </body>
            </html>`;
  }
}

extension.ts:

import * as vscode from "vscode";


const MY_COMMAND = "extension.hello";

export function activate(context: vscode.ExtensionContext) {
  const provider = new MyProvider(context.extensionUri);

  context.subscriptions.push(
    vscode.commands.registerCommand(MY_COMMAND, () => {
      provider.postMessageToWebview({
        type: "greeting",
        message: "HelloWorld",
      });
    })
  );

  context.subscriptions.push(
    vscode.window.registerWebviewViewProvider(
      MyProvider.viewType,
      provider
    )
  );
}

This console.log is showing that the this._view?.webview is undefined console.log("$#@$@#message", message, this._view?.webview);

The expected results is that executing the 'hello' command - it will send the message and show the console.log, show the webview view panel.

Expected type 'bool'. Found 'Illuminate\Auth\Access\Response'.intelephense(1006)

I am working on a Laravel 10 on Visual Studio Code with intelephense extension installed. I am getting error on my policy classes saying,

"Expected type 'bool'. Found 'Illuminate\Auth\Access\Response'.intelephense(1006)"

Here is a portion of my code:

public function create(User $user): bool
{
    $roles = $user->roles->pluck('id')->toArray();
    return in_array(Role::TRAINING_MANAGER, $roles)
        ? Response::allow()
        : Response::deny();
}

How to get ride of this error notification?

Update

I should have changed the return type to Response.

Is there a node executable shipped with vscode?

When I use the Remote Extension in vscode, I get a .vscode-server directory. Inside, I can find a node executable, e.g. in ~/.vscode-server/some-random-string/node.

I figured this out by testing the following minimal vscode extension:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('test.helloworld', () => {
        vscode.window.showInformationMessage(process.argv[0]); 
    });
    context.subscriptions.push(disposable);
}
export function deactivate() {}

Running the same extension without the Remote extension, e.g. within Windows, the same extension would show me that I am running vscode from:

C:\Users\username\AppData\Local\Programs\Microsoft VS Code\Code.exe

My question is: is there a node executable available somewhere within vscode (not using Remote Extension) and how to find its path reliably from a vscode extension?

This is what I see in the Microsoft VS Code directory:

Directories:

  • bin
  • locales
  • policies
  • resources
  • tools

as well as the Code.exe, and other irrelevant files. I looked everywhere but couldn't find any node executable.

There is also a ~/.vscode directory in my home folder, where you can find extensions, and an empty cli folder.

can't connect to remote machine using remote-ssh extension in vscode and got error that remote machine doesn't have bash with "sh: bash: not found"

my machine runs Windows10 and Vscode with remote-ssh extension that I am using to connect to the remote machine which runs a minimal customized Ubuntu18 version customized with build-root

currently, I have a Python Flask web app running on the remote machine and to add new features I am modifying and testing the web app code locally on my machine (Win10_machine) and then using the 'scp -r' command to copy these files to the remote machine (ubuntu18_machine) directory

and what I want to do is use the remote-ssh extension in vs code to remote to ubut18_machine and modify the web app files directly on the target from my machine to do that

  • I hit Ctrl+Shift+P to open vscode command letter and hit remote-ssh: connect current windows to host and then entered the usrname@IP of the remote machine and entered the target machine os type linux and then entered the password of the ssh connection and then I got this error window
couldn't establish connection to '192.168.xxx.xx': bash: not found.

and I checked the output window to see the procedure of connection and I got this

[02:38:38.167] Log Level: 2
[02:38:38.201] SSH Resolver called for "ssh-remote+7b22686f73744e616d65223a223139322e3136382e3137392e323438222c2275736572223a22726f6f74227d", attempt 1
[02:38:38.203] "remote.SSH.useLocalServer": false
[02:38:38.204] "remote.SSH.useExecServer": false
[02:38:38.206] "remote.SSH.showLoginTerminal": true
[02:38:38.206] "remote.SSH.remotePlatform": {"Axxc_Kit":"linux","192.168.179.92":"linux"}
[02:38:38.207] "remote.SSH.path": undefined
[02:38:38.207] "remote.SSH.configFile": C:\Users\Hazem\.ssh\axxclab_config
[02:38:38.208] "remote.SSH.useFlock": true
[02:38:38.208] "remote.SSH.lockfilesInTmp": false
[02:38:38.208] "remote.SSH.localServerDownload": auto
[02:38:38.209] "remote.SSH.remoteServerListenOnSocket": true
[02:38:38.221] "remote.SSH.showLoginTerminal": true
[02:38:38.222] "remote.SSH.defaultExtensions": []
[02:38:38.224] "remote.SSH.loglevel": 2
[02:38:38.225] "remote.SSH.enableDynamicForwarding": true
[02:38:38.226] "remote.SSH.enableRemoteCommand": true
[02:38:38.226] "remote.SSH.serverPickPortsFromRange": {}
[02:38:38.227] "remote.SSH.serverInstallPath": {}
[02:38:38.242] VS Code version: 1.84.2
[02:38:38.242] Remote-SSH version: [email protected]
[02:38:38.242] win32 x64
[02:38:38.244] SSH Resolver called for host: [email protected]
[02:38:38.244] Setting up SSH remote "192.168.179.248"
[02:38:38.254] Using commit id "1a5daa3a0231a0fbba4f14db7ec463cf99d7768e" and quality "stable" for server
[02:38:38.261] Install and start server if needed
[02:38:44.780] Checking ssh with "C:\WINDOWS\system32\ssh.exe -V"
[02:38:44.787] Got error from ssh: spawn C:\WINDOWS\system32\ssh.exe ENOENT
[02:38:44.788] Checking ssh with "C:\WINDOWS\ssh.exe -V"
[02:38:44.789] Got error from ssh: spawn C:\WINDOWS\ssh.exe ENOENT
[02:38:44.789] Checking ssh with "C:\WINDOWS\System32\Wbem\ssh.exe -V"
[02:38:44.793] Got error from ssh: spawn C:\WINDOWS\System32\Wbem\ssh.exe ENOENT
[02:38:44.794] Checking ssh with "C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[02:38:44.796] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[02:38:44.796] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V"
[02:38:44.854] > OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2

[02:38:44.865] Using SSH config file "C:\Users\Hazem\.ssh\axxclab_config"
[02:38:44.865] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 3198 -F "C:\Users\Hazem\.ssh\axxclab_config" "[email protected]" bash
[02:38:44.868] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[02:38:45.535] > ]0;C:\WINDOWS\System32\cmd.exe
[02:38:45.536] Got some output, clearing connection timeout
[02:38:45.552] > 
> 
> 
> 
> 
> 
[02:38:45.754] > [email protected]'s password: 
[02:38:49.879] > 
[02:38:50.078] > sh: bash: not found
[02:38:51.370] "install" terminal command done
[02:38:51.372] Install terminal quit with output: sh: bash: not found
[02:38:51.372] Received install output: sh: bash: not found
[02:38:51.377] Resolver error: Error: bash not found
    at g.Create (c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:642290)
    at c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:639024
    at t.handleInstallOutput (c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:639578)
    at t.tryInstall (c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:761636)
    at async c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:722175
    at async t.withShowDetailsEvent (c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:725481)
    at async I (c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:719146)
    at async t.resolve (c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:722852)
    at async c:\Users\Hazem\.vscode\extensions\ms-vscode-remote.remote-ssh-0.107.0\out\extension.js:2:906656
[02:38:51.412] ------

and after analyzing these logs I found that the remote-ssh extension executes this command

ssh -T -D 27584 -F "C:\Users\Hazem\.ssh\iowa_config" "192.168.179.248" bash

to establish the connection according to the extension configuration echoed at the beginning of the logs section

so what I and this command is actually executing bash which I don't have on the remote machine so that this step fails and closes the connection with such an error

so the question is how can I map remote directories locally and modify them from my local machine "win10_machine" as if they are located on my machine and modify them using Vscode

what is the best practice for such a thing?!!

any suggestion will be helpful thanks.

Django template error after parenthesis added by autoformat

I use VSCode and the Django Template Support extension for autoformatting templates. It adds parentheses to my code making it not work.

before:

{% elif n > page_obj.number|add:'-5' and n < page_obj.number|add:'5' %}

after:

{% elif n > (page_obj.number|add:'-5' and n < (page_obj.number|add:'5')) %}
Template error:
In template N:\Coding Projects\poc\templates\poc\product_list_grid.html, error at line 133
   Could not parse some characters: |(page_obj.number||add:'-5'
   123 :               <a class="page-link" href="?page=1" aria-label="First">
   124 :                 <span aria-hidden="true">&laquo;</span>
   125 :                 <span class="sr-only">First</span>
   126 :               </a>
   127 :             </li>
   128 :           {% endif %}
   129 : 
   130 :           <!-- with filter and pages in between -->
   131 :           {% for n in page_obj.paginator.page_range %}
   132 :             {% if request.GET.item_code or request.GET.brand__brand_name or request.GET.description %}
   133 :                {% if n == page_obj.number%} 
   134 :                 <li class="page-item active">
   135 :                   <span class="page-link"><b>{{ n }}</b><span class="sr-only"></span></span>
   136 :                 </li>
   137 :               {% elif n > (page_obj.number|add:'-5' and n < (page_obj.number|add:'5')) %}
   138 :                 <li class="page-item">
   139 :                   <a class="page-link" href="{% update_url n 'page' request.GET.urlencode %}">{{ n }}</a>
   140 :                 </li>
   141 :               {% endif %}
   142 : 
   143 :               <!-- without filter and pages in between -->

Is this a formatter issue? How can I solve this? Removing the parenthesis worked but then I have to do that to all my templates.

Removing the parenthesis worked but then I have to do that to all my templates.

Filtering and code completion do not work when '#' character is used

I've reproduced the problem in lsp-sample (description of my original post moved below).

The code completion does not work with # character. How to make it work?

Added CompletionItem for #1000:

connection.onCompletion(
    (_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
        return [
            {
                label: 'TypeScript',
                kind: CompletionItemKind.Text,
                data: 1,
            },
            {
                label: 'JavaScript',
                kind: CompletionItemKind.Text,
                data: 2,
            },
            {
                label: '#1000',
                kind: CompletionItemKind.Text,
                data: 3,
            },
        ];
    }
);

Now typing # or #1 does not show/filter the completion list. Choosing #1000 from the list does not completes properly, i.e. makes ##1000.

For filtering tried adding filterText: '#[0-9]+', or filterText: '#', to no avail.

For completion tried below but it does not work when there is something before #1 in the same line:

textEdit: InsertReplaceEdit.create(
                    '#1000',
                    Range.create(
                        Position.create(_textDocumentPosition.position.line, 0),
                        _textDocumentPosition.position
                    ),
                    Range.create(
                        Position.create(_textDocumentPosition.position.line, 0),
                        _textDocumentPosition.position
                    )
                ),

=================(My previous post)=======================

I have the following code completion list defined:

[
    {
        "jsonrpc": "2.0",
        "id": 6,
        "result": [
            {
                "label": "G253",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 106
            },
            {
                "label": "G254",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 107
            },
            {
                "label": "G255",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 108
            },
            {
                "label": "#3000",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 215
            },
            {
                "label": "#3001",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 216
            },
            {
                "label": "#3002",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 217
            },
            {
                "label": "#3003",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 218
            },
            {
                "label": "#3004",
                "kind": 15,
                "insertTextFormat": 2,
                "data": 219
            }
        ]
    }
]

When typing # and triggering code completion, further typing #3 does not make the list filtered. Then selecting for example #3002 from the list inserts double hash: ##3002. What am I missing here?

However there is no problem if I use other character than #, for example G. Then everything works with no problem - proper completion list filtering and inserting, for example G254.

Using R radian only on my own machine, not on remote server with vscode

I have installed radian and am using it perfectly on my own machine. However, when I try to ssh into another terminal and run R, it won't run, as it can't find radian in the r.path given.

I understand that the directory in my own computer will not lead anywhere in the remote machine. However, how do people use radian and SSH at all?

Side note, the remote machine does not have radian and I don't have authorization to install it, so ideally I'd like a solution that allows me to use radian on my home computer and vanilla R on the remote.

figure

rust-analyzer failed to discover workspace in vscode

I'm starting to learn the Rust language and I have an issue with rust-analyzer vscode extension.

This picture doesn't provide me with any additional info about root of the problem. I tried to find articles related to my error, but failed. Please help!

UPD1.

Screenshot of directory:

enter image description here

Screenshot of Cargo.toml contents:

enter image description here

guessing_game directory was created with cargo new guessing_game command

How to add a keybinding to a QuickPickItem in a VsCode Extension

In VsCode UX guidelines page there is an example that shows a keybinding in a QuickPickItem.

VsCode UI with a keybinding in the QuickPickItem

However, I cannot found any option in VsCode API to add it. I am only able to add this type of keybindings in commands in the file package.json

"keybindings": [
  {
    "command": "extension-name.option1",
    "key": "ctrl+g", 
    "mac": "cmd+g",   
    "linux": "ctrl+g",
    "win": "ctrl+g"   ,
  }

Is it possible to add the keybinding and the icon of the shortcut at the top right of the QuickPickItem like it's shown in the example?

Important, this should not only work, but be visible like in the example.

โŒ
โŒ