Skip to content
This repository has been archived by the owner on Nov 22, 2020. It is now read-only.

Fix URI creation from path #6

Open
aeschli opened this issue Aug 27, 2018 · 1 comment
Open

Fix URI creation from path #6

aeschli opened this issue Aug 27, 2018 · 1 comment

Comments

@aeschli
Copy link

aeschli commented Aug 27, 2018

In 1.26 we discovered that several extensions call the 'vscode.openFolder' command with invalid file URIs:

  `133,49:                 vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.parse(workingFolder));`
  `133,49:                 vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.parse(workingFolder));`
  `221,55:                 yield vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.parse(workingFolder));`

When creating a URI from a file path, always use vscode.URI.file(path), e.g vscode.URI.file('c:\\test')
Use vscode.URI.parse(uriString) when the input string is in the form scheme://authority/path

See microsoft/vscode#57267 for more information or for questions.

@minkir014
Copy link

minkir014 commented Apr 30, 2019

I saw that it works right there are four times only that he used Uri and it's in its place.

private showToolbarForActiveDocumentIfNeeded(documentUri: vscode.Uri) {
if (this.isMicropythonProject(documentUri))

'use strict';
import Base from '../base';
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import * as _ from 'lodash';

// Escape path spaces for REPL: /my awesome/file/path => '/my\ awesome/file/path'
const normalizePath = (path: string = ''): string => path.replace(/(\s+)/g, '\$1');

export default class Project extends Base {

/**

  • display main menu for project managerment
    */
    public async actionShowMainMenu() {
    let menuItems: vscode.QuickPickItem[] = [];
menuItems.push({
  label: "New project...",
  description: "",
  detail: "Generate new project included supported files"
});

menuItems.push({
  label: "Flash Firmware...",
  description: "",
  detail: "Flash Micropython firmware using esptool.py"
});

menuItems.push({
  label: "Download Firmware...",
  description: "",
  detail: "Enter Micropython download page"
});

let selectedAction = await vscode.window.showQuickPick(menuItems);
if (!selectedAction) { return; }

switch (selectedAction.label) {
  case 'New project...':
    this.actionNewProject();
    break;
  case 'Flash Firmware...':
    this.actionFlashFirmware();
    break;
  case 'Download Firmware...':
    vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('http://www.micropython.org/download'));

await vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.parse(workingFolder));
} catch (exception)

protected isMicropythonProject(documentPath: vscode.Uri) {
let projectPath = vscode.workspace.getWorkspaceFolder(documentPath);
if (!projectPath) { return false; }
return fs.existsSync(path.join(projectPath.uri.fsPath, Base.CONSTANTS.APP.CONFIG_FILE_NAME));
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants