diff --git a/Extension/src/LanguageServer/Providers/documentSymbolProvider.ts b/Extension/src/LanguageServer/Providers/documentSymbolProvider.ts index 7fd2488ca..62ea2d87f 100644 --- a/Extension/src/LanguageServer/Providers/documentSymbolProvider.ts +++ b/Extension/src/LanguageServer/Providers/documentSymbolProvider.ts @@ -3,7 +3,7 @@ * See 'LICENSE' in the project root for license information. * ------------------------------------------------------------------------------------------ */ import * as vscode from 'vscode'; -import { DefaultClient, LocalizeDocumentSymbol, GetDocumentSymbolRequestParams, GetDocumentSymbolRequest } from '../client'; +import { DefaultClient, LocalizeDocumentSymbol, GetDocumentSymbolRequestParams, GetDocumentSymbolRequest, SymbolScope } from '../client'; import * as util from '../../common'; import { processDelayedDidOpen } from '../extension'; @@ -16,7 +16,20 @@ export class DocumentSymbolProvider implements vscode.DocumentSymbolProvider { const documentSymbols: vscode.DocumentSymbol[] = []; if (symbols) { symbols.forEach((symbol) => { - const detail: string = util.getLocalizedString(symbol.detail); + let detail: string = util.getLocalizedString(symbol.detail); + if (symbol.scope === SymbolScope.Private) { + if (detail.length === 0) { + detail = "private"; + } else { + detail = util.getLocalizedSymbolScope("private", detail); + } + } else if (symbol.scope === SymbolScope.Protected) { + if (detail.length === 0) { + detail = "protected"; + } else { + detail = util.getLocalizedSymbolScope("protected", detail); + } + } const r: vscode.Range = new vscode.Range(symbol.range.start.line, symbol.range.start.character, symbol.range.end.line, symbol.range.end.character); const sr: vscode.Range = new vscode.Range(symbol.selectionRange.start.line, symbol.selectionRange.start.character, symbol.selectionRange.end.line, symbol.selectionRange.end.character); const vscodeSymbol: vscode.DocumentSymbol = new vscode.DocumentSymbol(symbol.name, detail, symbol.kind, r, sr); diff --git a/Extension/src/LanguageServer/Providers/workspaceSymbolProvider.ts b/Extension/src/LanguageServer/Providers/workspaceSymbolProvider.ts index b2b866694..726cd11fb 100644 --- a/Extension/src/LanguageServer/Providers/workspaceSymbolProvider.ts +++ b/Extension/src/LanguageServer/Providers/workspaceSymbolProvider.ts @@ -3,7 +3,7 @@ * See 'LICENSE' in the project root for license information. * ------------------------------------------------------------------------------------------ */ import * as vscode from 'vscode'; -import { DefaultClient, GetSymbolInfoRequest, WorkspaceSymbolParams, LocalizeSymbolInformation } from '../client'; +import { DefaultClient, GetSymbolInfoRequest, WorkspaceSymbolParams, LocalizeSymbolInformation, SymbolScope } from '../client'; import * as util from '../../common'; export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider { @@ -22,10 +22,21 @@ export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider { // Convert to vscode.Command array symbols.forEach((symbol) => { - const suffix: string = util.getLocalizedString(symbol.suffix); + let suffix: string = util.getLocalizedString(symbol.suffix); let name: string = symbol.name; if (suffix.length) { + if (symbol.scope === SymbolScope.Private) { + suffix = util.getLocalizedSymbolScope("private", suffix); + } else if (symbol.scope === SymbolScope.Protected) { + suffix = util.getLocalizedSymbolScope("protected", suffix); + } name = name + ' (' + suffix + ')'; + } else { + if (symbol.scope === SymbolScope.Private) { + name = name + " (private)"; + } else if (symbol.scope === SymbolScope.Protected) { + name = name + " (protected)"; + } } const range: vscode.Range = new vscode.Range(symbol.location.range.start.line, symbol.location.range.start.character, symbol.location.range.end.line, symbol.location.range.end.character); const uri: vscode.Uri = vscode.Uri.parse(symbol.location.uri.toString()); diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index d054c4c18..b48cf159e 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -297,10 +297,17 @@ export interface WorkspaceSymbolParams extends WorkspaceFolderParams { query: string; } +export enum SymbolScope { + Public = 0, + Protected = 1, + Private = 2 +} + export interface LocalizeDocumentSymbol { name: string; detail: LocalizeStringParams; kind: vscode.SymbolKind; + scope: SymbolScope; range: Range; selectionRange: Range; children: LocalizeDocumentSymbol[]; @@ -315,6 +322,7 @@ interface Location { export interface LocalizeSymbolInformation { name: string; kind: vscode.SymbolKind; + scope: SymbolScope; location: Location; containerName: string; suffix: LocalizeStringParams; diff --git a/Extension/src/common.ts b/Extension/src/common.ts index 6cd186eff..3d5bc68f9 100644 --- a/Extension/src/common.ts +++ b/Extension/src/common.ts @@ -257,19 +257,19 @@ export function isUri(input: any): input is vscode.Uri { } export function isString(input: any): input is string { - return typeof(input) === "string"; + return typeof (input) === "string"; } export function isNumber(input: any): input is number { - return typeof(input) === "number"; + return typeof (input) === "number"; } export function isBoolean(input: any): input is boolean { - return typeof(input) === "boolean"; + return typeof (input) === "boolean"; } export function isObject(input: any): input is object { - return typeof(input) === "object"; + return typeof (input) === "object"; } export function isArray(input: any): input is any[] { @@ -288,7 +288,7 @@ export function isOptionalArrayOfString(input: any): input is string[] | undefin return input === undefined || isArrayOfString(input); } -export function resolveCachePath(input: string | undefined, additionalEnvironment: {[key: string]: string | string[]}): string { +export function resolveCachePath(input: string | undefined, additionalEnvironment: { [key: string]: string | string[] }): string { let resolvedPath: string = ""; if (!input) { // If no path is set, return empty string to language service process, where it will set the default path as @@ -301,7 +301,7 @@ export function resolveCachePath(input: string | undefined, additionalEnvironmen return resolvedPath; } -export function resolveVariables(input: string | undefined, additionalEnvironment?: {[key: string]: string | string[]}): string { +export function resolveVariables(input: string | undefined, additionalEnvironment?: { [key: string]: string | string[] }): string { if (!input) { return ""; } @@ -981,7 +981,8 @@ export function extractCompilerPathAndArgs(inputCompilerPath?: string, inputComp if (compilerPath) { if (compilerPathLowercase?.endsWith("\\cl.exe") || compilerPathLowercase?.endsWith("/cl.exe") || (compilerPathLowercase === "cl.exe") - || compilerPathLowercase?.endsWith("\\cl") || compilerPathLowercase?.endsWith("/cl") || (compilerPathLowercase === "cl")) { compilerName = path.basename(compilerPath); + || compilerPathLowercase?.endsWith("\\cl") || compilerPathLowercase?.endsWith("/cl") || (compilerPathLowercase === "cl")) { + compilerName = path.basename(compilerPath); } else if (compilerPath.startsWith("\"")) { // Input has quotes around compiler path const endQuote: number = compilerPath.substr(1).search("\"") + 1; @@ -1049,7 +1050,7 @@ export function escapeForSquiggles(s: string): string { newResults += "\\"; } lastWasBackslash = false; - lastBackslashWasEscaped = false; + lastBackslashWasEscaped = false; newResults += s[i]; } } @@ -1142,6 +1143,13 @@ export function getLocalizedString(params: LocalizeStringParams): string { return indent + text; } +export function getLocalizedSymbolScope(scope: string, detail: string): string { + return localize({ + key: "c.cpp.symbolscope.separator", comment: + ["{0} is an untranslated C++ keyword (e.g. \"private\") and {1} is either another keyword (e.g. \"typedef\") or a localized property (e.g. a localized verison of \"declaration\""] + }, "{0}, {1}", scope, detail); +} + function decodeUCS16(input: string): number[] { const output: number[] = []; let counter: number = 0;