dphans / micropython-ide-vscode

Micropython integrated development for VSCode
Apache License 2.0
57 stars 34 forks source link

Fix URI creation from path #6

Open aeschli opened 6 years ago

aeschli commented 6 years ago

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 https://github.com/Microsoft/vscode/issues/57267 for more information or for questions.

minkir014 commented 5 years ago

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 {

/**

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)); }