diff --git a/CHANGELOG.md b/CHANGELOG.md index d945883..dbc1287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ See the full list of recent releases and features added on the [Github releases page](https://github.com/PranayAgarwal/vscode-hack/releases). +## v0.8.1 - 2018-05-14 +- Updated Hack language syntax to the latest version +- Removed some unnecessary PHP snippets +- Fixed file path mapping in typechecker requests & responses to use the correct scheme (thanks [@fredemmott](https://github.com/fredemmott) for the thorough investigation) + ## v0.8.0 - 2018-05-10 - **HHVM Debugger (Alpha version)** — Launch scripts or attach to an HHVM server straight from VS Code. See the [debugger doc](https://github.com/PranayAgarwal/vscode-hack/blob/master/docs/debugging.md) for details on setup and usage. _This is a very early release. Please file any bugs at the Issues page._ - Hack coverage check works again. A new icon in the editor status bar shows % coverage for the file and can be clicked to highlight uncovered areas. (Can be disabled by setting `"hack.enableCoverageCheck": false`) diff --git a/README.md b/README.md index c2f11f0..7e464d9 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ It is published in the Visual Studio Marketplace [here](https://marketplace.visu ## Latest releases +## v0.8.1 +- Updated Hack language syntax to the latest version +- Removed some unnecessary PHP snippets +- Fixed file path mapping in typechecker requests & responses to use the correct scheme (thanks [@fredemmott](https://github.com/fredemmott) for the thorough investigation) + ## v0.8.0 - **HHVM Debugger (Alpha version)** — Launch scripts or attach to an HHVM server straight from VS Code. See the [debugger doc](https://github.com/PranayAgarwal/vscode-hack/blob/master/docs/debugging.md) for details on setup and usage. _This is a very early release. Please file any bugs at the Issues page._ - Hack coverage check works again. A new icon in the editor status bar shows % coverage for the file and can be clicked to highlight uncovered areas. (Can be disabled by setting `"hack.enableCoverageCheck": false`) diff --git a/package.json b/package.json index a57a91d..c3ea46b 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vscode-hack", - "version": "0.8.0", + "version": "0.8.1", "publisher": "pranayagarwal", "engines": { "vscode": "^1.18.0" diff --git a/src/Config.ts b/src/Config.ts index b4ecaa1..3297fac 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -11,7 +11,15 @@ export const clientPath: string = hackConfig.get('clientPath') || 'hh_client'; export const hhClientArgs: string[] = clientPath.split(' '); export const hhClientCommand: string = String(hhClientArgs.shift()); -export const workspace: string = hackConfig.get('workspaceRootPath') || vscode.workspace.rootPath || ''; +export let mapWorkspace: boolean = false; +export let workspace: string; +const workspaceRootPath: string | undefined = hackConfig.get('workspaceRootPath'); +if (workspaceRootPath) { + mapWorkspace = true; + workspace = workspaceRootPath; +} else if (vscode.workspace.workspaceFolders) { + workspace = vscode.workspace.workspaceFolders[0].uri.fsPath; +} let enableCoverageCheckConfig: boolean | undefined = hackConfig.get('enableConverageCheck'); if (enableCoverageCheckConfig === undefined) { diff --git a/src/Utils.ts b/src/Utils.ts index f5f63c5..d5fc929 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -6,43 +6,38 @@ import * as vscode from 'vscode'; import * as config from './Config'; /** - * If a workspace mapping is specified in vscode settings, convert a local workspace file - * path's root to the configured alternate path. - * @param fileName The file path to convert + * Converts a local workspace URI to a file path string (with or without scheme) to pass to + * the typechecker. Path is mapped to an alternate workspace root if configured. + * @param file The file URI to convert + * @param includeScheme Whether to include the file:// scheme in the response or not */ -export const mapFromWorkspacePath = (fileName: string) => { - if (config.workspace && vscode.workspace.rootPath) { - return fileName.replace(vscode.workspace.rootPath, config.workspace); +export const mapFromWorkspaceUri = (file: vscode.Uri, includeScheme: boolean = true): string => { + if (!config.mapWorkspace && includeScheme) { + return file.toString(); } - return fileName; -}; - -/** - * If a workspace mapping is specified in vscode settings, convert a mapped file path's - * root back to the local workspace. - * @param fileName The file path to convert - */ -export const mapToWorkspacePath = (fileName: string) => { - if (config.workspace && vscode.workspace.rootPath) { - return fileName.replace(config.workspace, vscode.workspace.rootPath); + let filePath = file.fsPath; + if (config.mapWorkspace && vscode.workspace.workspaceFolders) { + filePath = filePath.replace(vscode.workspace.workspaceFolders[0].uri.fsPath, config.workspace); } - return fileName; -}; - -/** - * Converts a local workspace URI to a file path string, mapping path to an - * alternate workspace root if configured. - * @param value The file URI to convert - */ -export const mapFromWorkspaceUri = (value: vscode.Uri) => { - return mapFromWorkspacePath(value.fsPath); + if (includeScheme) { + return vscode.Uri.file(filePath).toString(); + } + return filePath; }; /** - * Converts a file path string to a local workspace URI, mapping from an - * alternate workspace root if configured. - * @param value The file path to convert + * Converts a file path string received from the typechecker to a local workspace URI. + * Path is mapped from an alternate workspace root if configured. + * @param file The file path to convert */ -export const mapToWorkspaceUri = (value: string) => { - return vscode.Uri.parse(mapToWorkspacePath(value)); +export const mapToWorkspaceUri = (file: string): vscode.Uri => { + let filePath = file; + if (config.mapWorkspace && vscode.workspace.workspaceFolders) { + filePath = filePath.replace(config.workspace, vscode.workspace.workspaceFolders[0].uri.fsPath); + } + if (filePath.startsWith('file://')) { + return vscode.Uri.parse(filePath); + } else { + return vscode.Uri.file(filePath); + } }; diff --git a/src/coveragechecker.ts b/src/coveragechecker.ts index d0ad655..79efa8c 100644 --- a/src/coveragechecker.ts +++ b/src/coveragechecker.ts @@ -7,10 +7,10 @@ import * as hh_client from './proxy'; import * as utils from './Utils'; type UnfilteredTypeCoverageRegion = { - regionType: string, - line: number, - start: number, - end: number + regionType: string; + line: number; + start: number; + end: number; }; export class HackCoverageChecker { @@ -36,8 +36,8 @@ export class HackCoverageChecker { * until hhvm returns a better response for coverage runs. * */ - private static convertTypedRegionsToCoverageResult(regions: { color: string, text: string }[]) - : { percentage: number, uncoveredRegions: UnfilteredTypeCoverageRegion[] } { + private static convertTypedRegionsToCoverageResult(regions: { color: string; text: string }[]) + : { percentage: number; uncoveredRegions: UnfilteredTypeCoverageRegion[] } { const startColumn = 1; let line = 1; let column = startColumn; @@ -135,7 +135,7 @@ export class HackCoverageChecker { this.coverageStatus.hide(); return; } - const colorResult = await hh_client.color(utils.mapFromWorkspacePath(document.fileName)); + const colorResult = await hh_client.color(utils.mapFromWorkspaceUri(document.uri, false)); if (!colorResult) { this.coverageStatus.hide(); return; diff --git a/src/providers.ts b/src/providers.ts index 3f2a6e4..e162c27 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -51,7 +51,6 @@ const pushSymbols = (outline: OutlineResponse[], symbols: vscode.SymbolInformati name += '()'; break; default: - break; } name = indent + name; const range = getRange(element.span.line_start, element.span.line_end, element.span.char_start, element.span.char_end); @@ -74,7 +73,7 @@ export class HackHoverProvider implements vscode.HoverProvider { const startPosition = wordPosition.start; const line: number = startPosition.line + 1; const character: number = startPosition.character + 1; - return hh_client.typeAtPos(utils.mapFromWorkspacePath(document.fileName), line, character).then(hoverType => { + return hh_client.typeAtPos(utils.mapFromWorkspaceUri(document.uri, false), line, character).then(hoverType => { if (!hoverType) { return; } @@ -108,7 +107,7 @@ export class HackWorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvid desc = desc.slice(0, element.desc.indexOf(' in ')); } const kind = getSymbolKind(desc); - const uri: vscode.Uri = vscode.Uri.file(utils.mapToWorkspacePath(element.filename)); + const uri: vscode.Uri = utils.mapToWorkspaceUri(element.filename); const container = element.scope || (element.name.includes('\\') ? element.name.slice(0, element.name.lastIndexOf('\\')) : undefined); const range = getRange(element.line, element.line, element.char_start, element.char_end); symbols.push(new vscode.SymbolInformation(name, kind, range, uri, container)); @@ -190,7 +189,7 @@ export class HackReferenceProvider implements vscode.ReferenceProvider { const locations: vscode.Location[] = []; foundRefs.forEach(ref => { const location = new vscode.Location( - vscode.Uri.file(utils.mapToWorkspacePath(ref.filename)), + utils.mapToWorkspaceUri(ref.filename), new vscode.Range( new vscode.Position(ref.line - 1, ref.char_start - 1), new vscode.Position(ref.line - 1, ref.char_end))); @@ -218,7 +217,7 @@ export class HackDefinitionProvider implements vscode.DefinitionProvider { foundDefinition.forEach(element => { if (element.definition_pos) { const location: vscode.Location = new vscode.Location( - vscode.Uri.file(utils.mapToWorkspacePath(element.definition_pos.filename) || document.fileName), + element.definition_pos.filename ? utils.mapToWorkspaceUri(element.definition_pos.filename) : document.uri, new vscode.Range( new vscode.Position(element.definition_pos.line - 1, element.definition_pos.char_start - 1), new vscode.Position(element.definition_pos.line - 1, element.definition_pos.char_end))); diff --git a/src/typechecker.ts b/src/typechecker.ts index 5bbf068..856b11f 100644 --- a/src/typechecker.ts +++ b/src/typechecker.ts @@ -21,7 +21,7 @@ export class HackTypeChecker { return; } - const diagnosticMap: Map = new Map(); + const diagnosticMap: Map = new Map(); typecheckResult.errors.forEach(error => { let fullMessage = ''; let code: number = 0; @@ -39,7 +39,7 @@ export class HackTypeChecker { vscode.DiagnosticSeverity.Error); diagnostic.code = code; diagnostic.source = 'Hack'; - const file = utils.mapToWorkspacePath(error.message[0].path); + const file = utils.mapToWorkspaceUri(error.message[0].path); const cachedFileDiagnostics = diagnosticMap.get(file); if (cachedFileDiagnostics) { cachedFileDiagnostics.push(diagnostic); @@ -48,7 +48,7 @@ export class HackTypeChecker { } }); diagnosticMap.forEach((diags, file) => { - this.hhvmTypeDiag.set(vscode.Uri.file(file), diags); + this.hhvmTypeDiag.set(file, diags); }); } }