Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fa1b162
Refactored provider classes from client.ts
spacemonkd Aug 21, 2020
18b7f8d
Fixed lint errors in Azure pipeline
spacemonkd Aug 21, 2020
ea26e53
Merge branch 'master' into provider_5871
sean-mcmanus Aug 21, 2020
8e2b2e6
Added comment lines for azure pipeline error
spacemonkd Aug 21, 2020
d390344
Merge branch 'provider_5871' of https://github.com/devabhishekpal/vsc…
spacemonkd Aug 21, 2020
5aa64f1
Created individual files for providers
spacemonkd Aug 22, 2020
4266495
Fixed linting issues
spacemonkd Aug 22, 2020
7422993
Merge branch 'master' into provider_5871
spacemonkd Aug 22, 2020
02cc49b
Refixed spaces for linting
spacemonkd Aug 22, 2020
64cf927
Merge branch 'provider_5871' of https://github.com/devabhishekpal/vsc…
spacemonkd Aug 22, 2020
834bfbc
Add localization title and changed sentence
spacemonkd Aug 25, 2020
f9c1dec
Deleted wrong commit
spacemonkd Aug 25, 2020
d688979
Moved all providers to Providers folder and removed holder classes
spacemonkd Aug 26, 2020
babafd2
Merge branch 'master' into provider_5871
spacemonkd Aug 26, 2020
ff24cdf
Refactored the params into DefaultClient as static members
spacemonkd Sep 2, 2020
536a94c
Revert "Refactored the params into DefaultClient as static members"
spacemonkd Sep 4, 2020
d04aa1c
Undo previous commit and changing variables to public static
spacemonkd Sep 4, 2020
66a9890
Revert "Undo previous commit and changing variables to public static"
spacemonkd Sep 5, 2020
e1596fe
Updated client with current master and fixed extra spaces
spacemonkd Sep 5, 2020
58e60ac
Merge branch 'master' into provider_5871
sean-mcmanus Sep 8, 2020
dd1ab75
Fixed eror on line 1360
spacemonkd Sep 9, 2020
99b956c
Update client.ts
spacemonkd Sep 9, 2020
b5ac4e8
Update .eslintrc.js
spacemonkd Sep 10, 2020
75b4240
Update client.ts
spacemonkd Sep 10, 2020
2f35092
Update documentFormattingEditProvider.ts
spacemonkd Sep 10, 2020
888d386
Update documentSymbolProvider.ts
spacemonkd Sep 10, 2020
be06726
Update onTypeFormattingEditProvider.ts
spacemonkd Sep 10, 2020
c1a5f25
Update renameProvider.ts
spacemonkd Sep 10, 2020
6aab5a1
Merge branch 'master' into provider_5871
spacemonkd Sep 10, 2020
fc72913
Merge branch 'master' into provider_5871
sean-mcmanus Sep 14, 2020
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
2 changes: 1 addition & 1 deletion Extension/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
"no-fallthrough": "error",
"no-invalid-this": "error",
"no-irregular-whitespace": "error",
"no-multiple-empty-lines": "error",
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1, "maxBOF": 0}],
"no-new-wrappers": "error",
"no-redeclare": "error",
"no-return-await": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { DefaultClient, FormatParams, FormatDocumentRequest, cachedEditorConfigSettings } from '../client';
import { CppSettings } from '../settings';
import * as editorConfig from 'editorconfig';

export class DocumentFormattingEditProvider implements vscode.DocumentFormattingEditProvider {
private client: DefaultClient;
constructor(client: DefaultClient) {
this.client = client;
}

public provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Promise<vscode.TextEdit[]> {
return new Promise<vscode.TextEdit[]>((resolve, reject) => {
this.client.notifyWhenReady(() => {
const filePath: string = document.uri.fsPath;
const configCallBack = (editorConfigSettings: any | undefined) => {
const params: FormatParams = {
settings: { ...editorConfigSettings },
uri: document.uri.toString(),
insertSpaces: options.insertSpaces,
tabSize: options.tabSize,
character: "",
range: {
start: {
character: 0,
line: 0
},
end: {
character: 0,
line: 0
}
}
};
return this.client.languageClient.sendRequest(FormatDocumentRequest, params)
.then((textEdits) => {
const result: vscode.TextEdit[] = [];
textEdits.forEach((textEdit) => {
result.push({
range: new vscode.Range(textEdit.range.start.line, textEdit.range.start.character, textEdit.range.end.line, textEdit.range.end.character),
newText: textEdit.newText
});
});
resolve(result);
});
};
const settings: CppSettings = new CppSettings();
if (settings.formattingEngine !== "vcFormat") {
configCallBack(undefined);
} else {
const editorConfigSettings: any = cachedEditorConfigSettings.get(filePath);
if (!editorConfigSettings) {
editorConfig.parse(filePath).then(configCallBack);
} else {
cachedEditorConfigSettings.set(filePath, editorConfigSettings);
configCallBack(editorConfigSettings);
}
}
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { DefaultClient, FormatParams, FormatRangeRequest, cachedEditorConfigSettings } from '../client';
import { CppSettings } from '../settings';
import * as editorConfig from 'editorconfig';

export class DocumentRangeFormattingEditProvider implements vscode.DocumentRangeFormattingEditProvider {
private client: DefaultClient;
constructor(client: DefaultClient) {
this.client = client;
}

public provideDocumentRangeFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions, token: vscode.CancellationToken): Promise<vscode.TextEdit[]> {
return new Promise<vscode.TextEdit[]>((resolve, reject) => {
this.client.notifyWhenReady(() => {
const filePath: string = document.uri.fsPath;
const configCallBack = (editorConfigSettings: any | undefined) => {
const params: FormatParams = {
settings: { ...editorConfigSettings },
uri: document.uri.toString(),
insertSpaces: options.insertSpaces,
tabSize: options.tabSize,
character: "",
range: {
start: {
character: range.start.character,
line: range.start.line
},
end: {
character: range.end.character,
line: range.end.line
}
}
};
return this.client.languageClient.sendRequest(FormatRangeRequest, params)
.then((textEdits) => {
const result: vscode.TextEdit[] = [];
textEdits.forEach((textEdit) => {
result.push({
range: new vscode.Range(textEdit.range.start.line, textEdit.range.start.character, textEdit.range.end.line, textEdit.range.end.character),
newText: textEdit.newText
});
});
resolve(result);
});
};
const settings: CppSettings = new CppSettings();
if (settings.formattingEngine !== "vcFormat") {
configCallBack(undefined);
} else {
const editorConfigSettings: any = cachedEditorConfigSettings.get(filePath);
if (!editorConfigSettings) {
editorConfig.parse(filePath).then(configCallBack);
} else {
cachedEditorConfigSettings.set(filePath, editorConfigSettings);
configCallBack(editorConfigSettings);
}
}
});
});
};
}
40 changes: 40 additions & 0 deletions Extension/src/LanguageServer/Providers/documentSymbolProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { DefaultClient, LocalizeDocumentSymbol, GetDocumentSymbolRequestParams, GetDocumentSymbolRequest } from '../client';
import * as util from '../../common';

export class DocumentSymbolProvider implements vscode.DocumentSymbolProvider {
private client: DefaultClient;
constructor(client: DefaultClient) {
this.client = client;
}
private getChildrenSymbols(symbols: LocalizeDocumentSymbol[]): vscode.DocumentSymbol[] {
const documentSymbols: vscode.DocumentSymbol[] = [];
if (symbols) {
symbols.forEach((symbol) => {
const detail: string = util.getLocalizedString(symbol.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);
vscodeSymbol.children = this.getChildrenSymbols(symbol.children);
documentSymbols.push(vscodeSymbol);
});
}
return documentSymbols;
}
public async provideDocumentSymbols(document: vscode.TextDocument): Promise<vscode.SymbolInformation[] | vscode.DocumentSymbol[]> {
return this.client.requestWhenReady(() => {
const params: GetDocumentSymbolRequestParams = {
uri: document.uri.toString()
};
return this.client.languageClient.sendRequest(GetDocumentSymbolRequest, params)
.then((symbols) => {
const resultSymbols: vscode.DocumentSymbol[] = this.getChildrenSymbols(symbols);
return resultSymbols;
});
});
}
}
109 changes: 109 additions & 0 deletions Extension/src/LanguageServer/Providers/findAllReferencesProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { DefaultClient, workspaceReferences, FindAllReferencesParams, ReferencesCancellationState, RequestReferencesNotification, CancelReferencesNotification } from '../client';
import { Position } from 'vscode-languageclient';
import * as refs from '../references';

export class FindAllReferencesProvider implements vscode.ReferenceProvider {
private client: DefaultClient;
constructor(client: DefaultClient) {
this.client = client;
}
public async provideReferences(document: vscode.TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): Promise<vscode.Location[] | undefined> {
return new Promise<vscode.Location[]>((resolve, reject) => {
const callback: () => void = () => {
const params: FindAllReferencesParams = {
position: Position.create(position.line, position.character),
textDocument: this.client.languageClient.code2ProtocolConverter.asTextDocumentIdentifier(document)
};
DefaultClient.referencesParams = params;
this.client.notifyWhenReady(() => {
// The current request is represented by referencesParams. If a request detects
// referencesParams does not match the object used when creating the request, abort it.
if (params !== DefaultClient.referencesParams) {
// Complete with nothing instead of rejecting, to avoid an error message from VS Code
const locations: vscode.Location[] = [];
resolve(locations);
return;
}
DefaultClient.referencesRequestPending = true;
// Register a single-fire handler for the reply.
const resultCallback: refs.ReferencesResultCallback = (result: refs.ReferencesResult | null, doResolve: boolean) => {
DefaultClient.referencesRequestPending = false;
const locations: vscode.Location[] = [];
if (result) {
result.referenceInfos.forEach((referenceInfo: refs.ReferenceInfo) => {
if (referenceInfo.type === refs.ReferenceType.Confirmed) {
const uri: vscode.Uri = vscode.Uri.file(referenceInfo.file);
const range: vscode.Range = new vscode.Range(referenceInfo.position.line, referenceInfo.position.character, referenceInfo.position.line, referenceInfo.position.character + result.text.length);
locations.push(new vscode.Location(uri, range));
}
});
}
// If references were canceled while in a preview state, there is not an outstanding promise.
if (doResolve) {
resolve(locations);
}
if (DefaultClient.referencesPendingCancellations.length > 0) {
while (DefaultClient.referencesPendingCancellations.length > 1) {
const pendingCancel: ReferencesCancellationState = DefaultClient.referencesPendingCancellations[0];
DefaultClient.referencesPendingCancellations.pop();
pendingCancel.reject();
}
const pendingCancel: ReferencesCancellationState = DefaultClient.referencesPendingCancellations[0];
DefaultClient.referencesPendingCancellations.pop();
pendingCancel.callback();
}
};
if (!workspaceReferences.referencesRefreshPending) {
workspaceReferences.setResultsCallback(resultCallback);
workspaceReferences.startFindAllReferences(params);
} else {
// We are responding to a refresh (preview or final result)
workspaceReferences.referencesRefreshPending = false;
if (workspaceReferences.lastResults) {
// This is a final result
const lastResults: refs.ReferencesResult = workspaceReferences.lastResults;
workspaceReferences.lastResults = null;
resultCallback(lastResults, true);
} else {
// This is a preview (2nd or later preview)
workspaceReferences.referencesRequestPending = true;
workspaceReferences.setResultsCallback(resultCallback);
this.client.languageClient.sendNotification(RequestReferencesNotification, false);
}
}
});
token.onCancellationRequested(e => {
if (params === DefaultClient.referencesParams) {
this.client.cancelReferences();
}
});
};

if (DefaultClient.referencesRequestPending || (workspaceReferences.symbolSearchInProgress && !workspaceReferences.referencesRefreshPending)) {
const cancelling: boolean = DefaultClient.referencesPendingCancellations.length > 0;
DefaultClient.referencesPendingCancellations.push({
reject: () => {
// Complete with nothing instead of rejecting, to avoid an error message from VS Code
const locations: vscode.Location[] = [];
resolve(locations);
}, callback
});
if (!cancelling) {
DefaultClient.renamePending = false;
workspaceReferences.referencesCanceled = true;
if (!DefaultClient.referencesRequestPending) {
workspaceReferences.referencesCanceledWhilePreviewing = true;
}
this.client.languageClient.sendNotification(CancelReferencesNotification);
}
} else {
callback();
}
});
}
}
55 changes: 55 additions & 0 deletions Extension/src/LanguageServer/Providers/foldingRangeProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import { DefaultClient, GetFoldingRangesParams, GetFoldingRangesRequest, FoldingRangeKind } from '../client';

export class FoldingRangeProvider implements vscode.FoldingRangeProvider {
private client: DefaultClient;
constructor(client: DefaultClient) {
this.client = client;
}
provideFoldingRanges(document: vscode.TextDocument, context: vscode.FoldingContext,
token: vscode.CancellationToken): Promise<vscode.FoldingRange[]> {
const id: number = ++DefaultClient.abortRequestId;
const params: GetFoldingRangesParams = {
id: id,
uri: document.uri.toString()
};
return new Promise<vscode.FoldingRange[]>((resolve, reject) => {
this.client.notifyWhenReady(() => {
this.client.languageClient.sendRequest(GetFoldingRangesRequest, params)
.then((ranges) => {
if (ranges.canceled) {
reject();
} else {
const result: vscode.FoldingRange[] = [];
ranges.ranges.forEach((r) => {
const foldingRange: vscode.FoldingRange = {
start: r.range.start.line,
end: r.range.end.line
};
switch (r.kind) {
case FoldingRangeKind.Comment:
foldingRange.kind = vscode.FoldingRangeKind.Comment;
break;
case FoldingRangeKind.Imports:
foldingRange.kind = vscode.FoldingRangeKind.Imports;
break;
case FoldingRangeKind.Region:
foldingRange.kind = vscode.FoldingRangeKind.Region;
break;
default:
break;
}
result.push(foldingRange);
});
resolve(result);
}
});
token.onCancellationRequested(e => this.client.abortRequest(id));
});
});
}
}
Loading