Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symbol scopes. #7556

Merged
merged 9 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Extension/src/LanguageServer/Providers/documentSymbolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
* 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';
import * as nls from 'vscode-nls';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

export class DocumentSymbolProvider implements vscode.DocumentSymbolProvider {
private client: DefaultClient;
Expand All @@ -16,7 +20,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 = localize("c.cpp.symbolscope.separator", "{0}, {1}", "private", detail);
}
} else if (symbol.scope === SymbolScope.Protected) {
if (detail.length === 0) {
detail = "protected";
} else {
detail = localize("c.cpp.symbolscope.separator", "{0}, {1}", "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);
Expand Down
19 changes: 17 additions & 2 deletions Extension/src/LanguageServer/Providers/workspaceSymbolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
* 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';
import * as nls from 'vscode-nls';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

export class WorkspaceSymbolProvider implements vscode.WorkspaceSymbolProvider {
private client: DefaultClient;
Expand All @@ -22,10 +26,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 = localize("c.cpp.symbolscope.separator", "{0}, {1}", "private", suffix);
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
} else if (symbol.scope === SymbolScope.Protected) {
suffix = localize("c.cpp.symbolscope.separator", "{0}, {1}", "protected", suffix);
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
}
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());
Expand Down
8 changes: 8 additions & 0 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -315,6 +322,7 @@ interface Location {
export interface LocalizeSymbolInformation {
name: string;
kind: vscode.SymbolKind;
scope: SymbolScope;
location: Location;
containerName: string;
suffix: LocalizeStringParams;
Expand Down