mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Merge branch 'master' into joh/outline
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
||||
import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Disposable, Uri } from 'vscode';
|
||||
import { CancellationTokenSource, Disposable, TextDocument, TextDocumentChangeEvent, TextDocumentContentChangeEvent, Uri, workspace } from 'vscode';
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { Delayer } from '../utils/async';
|
||||
import * as languageModeIds from '../utils/languageModeIds';
|
||||
import { disposeAll } from '../utils/dipose';
|
||||
import * as languageModeIds from '../utils/languageModeIds';
|
||||
|
||||
|
||||
interface IDiagnosticRequestor {
|
||||
requestDiagnostic(resource: Uri): void;
|
||||
@@ -153,6 +153,7 @@ export default class BufferSyncSupport {
|
||||
|
||||
private readonly pendingDiagnostics = new Map<string, number>();
|
||||
private readonly diagnosticDelayer: Delayer<any>;
|
||||
private pendingGetErr: { request: Promise<any>, files: string[], token: CancellationTokenSource } | undefined;
|
||||
|
||||
constructor(
|
||||
client: ITypeScriptServiceClient,
|
||||
@@ -233,6 +234,10 @@ export default class BufferSyncSupport {
|
||||
const syncedBuffer = this.syncedBuffers.get(e.document.uri);
|
||||
if (syncedBuffer) {
|
||||
syncedBuffer.onContentChanged(e.contentChanges);
|
||||
if (this.pendingGetErr) {
|
||||
this.pendingGetErr.token.cancel();
|
||||
this.pendingGetErr = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,23 +284,42 @@ export default class BufferSyncSupport {
|
||||
if (!this._validate) {
|
||||
return;
|
||||
}
|
||||
const files = Array.from(this.pendingDiagnostics.entries())
|
||||
const files = new Set(Array.from(this.pendingDiagnostics.entries())
|
||||
.sort((a, b) => a[1] - b[1])
|
||||
.map(entry => entry[0]);
|
||||
.map(entry => entry[0]));
|
||||
|
||||
// Add all open TS buffers to the geterr request. They might be visible
|
||||
for (const file of this.syncedBuffers.allResources) {
|
||||
if (!this.pendingDiagnostics.get(file)) {
|
||||
files.push(file);
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (files.length) {
|
||||
if (this.pendingGetErr) {
|
||||
for (const file of this.pendingGetErr.files) {
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (files.size) {
|
||||
const fileList = Array.from(files);
|
||||
const args: Proto.GeterrRequestArgs = {
|
||||
delay: 0,
|
||||
files: files
|
||||
files: fileList
|
||||
};
|
||||
const token = new CancellationTokenSource();
|
||||
|
||||
const getErr = this.pendingGetErr = {
|
||||
request: this.client.execute('geterr', args, token.token)
|
||||
.then(undefined, () => { })
|
||||
.then(() => {
|
||||
if (this.pendingGetErr === getErr) {
|
||||
this.pendingGetErr = undefined;
|
||||
}
|
||||
}),
|
||||
files: fileList,
|
||||
token
|
||||
};
|
||||
this.client.execute('geterr', args, false);
|
||||
}
|
||||
this.pendingDiagnostics.clear();
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ export default class FileConfigurationManager {
|
||||
isTypeScriptDocument(document) ? 'typescript' : 'javascript',
|
||||
document.uri);
|
||||
|
||||
const preferences = config.workspace.getConfiguration(
|
||||
const preferences = workspace.getConfiguration(
|
||||
isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences',
|
||||
document.uri);
|
||||
|
||||
|
||||
@@ -34,13 +34,30 @@ export default class TypeScriptFoldingProvider implements vscode.FoldingRangePro
|
||||
return;
|
||||
}
|
||||
|
||||
return response.body.map(span => {
|
||||
const range = typeConverters.Range.fromTextSpan(span.textSpan);
|
||||
// workaround for #47240
|
||||
if (range.end.character > 0 && document.getText(new vscode.Range(range.end.translate(0, -1), range.end)) === '}') {
|
||||
return new vscode.FoldingRange(range.start.line, Math.max(range.end.line - 1, range.start.line));
|
||||
}
|
||||
return new vscode.FoldingRange(range.start.line, range.end.line);
|
||||
});
|
||||
return response.body.map(span => this.convertOutliningSpan(span, document));
|
||||
}
|
||||
|
||||
private convertOutliningSpan(span: Proto.OutliningSpan, document: vscode.TextDocument): vscode.FoldingRange {
|
||||
const range = typeConverters.Range.fromTextSpan(span.textSpan);
|
||||
const kind = TypeScriptFoldingProvider.getFoldingRangeKind(span);
|
||||
|
||||
const start = range.start.line;
|
||||
// workaround for #47240
|
||||
const end = (range.end.character > 0 && document.getText(new vscode.Range(range.end.translate(0, -1), range.end)) === '}')
|
||||
? Math.max(range.end.line - 1, range.start.line)
|
||||
: range.end.line;
|
||||
|
||||
return new vscode.FoldingRange(start, end, kind);
|
||||
}
|
||||
|
||||
private static getFoldingRangeKind(span: Proto.OutliningSpan): vscode.FoldingRangeKind | undefined {
|
||||
// TODO: remove cast once we get a new TS insiders
|
||||
switch ((span as Proto.OutliningSpan & { kind: any }).kind) {
|
||||
case 'comment': return vscode.FoldingRangeKind.Comment;
|
||||
case 'region': return vscode.FoldingRangeKind.Region;
|
||||
case 'imports': return vscode.FoldingRangeKind.Imports;
|
||||
case 'code':
|
||||
default: return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as nls from 'vscode-nls';
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { Command, CommandManager } from '../utils/commandManager';
|
||||
import { isSupportedLanguageMode } from '../utils/languageModeIds';
|
||||
import * as typeconverts from '../utils/typeConverters';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
@@ -23,21 +22,11 @@ class OrganizeImportsCommand implements Command {
|
||||
private readonly client: ITypeScriptServiceClient
|
||||
) { }
|
||||
|
||||
public async execute(): Promise<boolean> {
|
||||
public async execute(file: string): Promise<boolean> {
|
||||
if (!this.client.apiVersion.has280Features()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || !isSupportedLanguageMode(editor.document)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const file = this.client.normalizePath(editor.document.uri);
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const args: Proto.OrganizeImportsRequestArgs = {
|
||||
scope: {
|
||||
type: 'file',
|
||||
@@ -69,7 +58,7 @@ export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvi
|
||||
};
|
||||
|
||||
public provideCodeActions(
|
||||
_document: vscode.TextDocument,
|
||||
document: vscode.TextDocument,
|
||||
_range: vscode.Range,
|
||||
_context: vscode.CodeActionContext,
|
||||
_token: vscode.CancellationToken
|
||||
@@ -78,10 +67,15 @@ export class OrganizeImportsCodeActionProvider implements vscode.CodeActionProvi
|
||||
return [];
|
||||
}
|
||||
|
||||
const file = this.client.normalizePath(document.uri);
|
||||
if (!file) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const action = new vscode.CodeAction(
|
||||
localize('oraganizeImportsAction.title', "Organize Imports"),
|
||||
vscode.CodeActionKind.SourceOrganizeImports);
|
||||
action.command = { title: '', command: OrganizeImportsCommand.Id };
|
||||
action.command = { title: '', command: OrganizeImportsCommand.Id, arguments: [file] };
|
||||
return [action];
|
||||
}
|
||||
}
|
||||
@@ -804,6 +804,13 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
|
||||
private dispatchEvent(event: Proto.Event) {
|
||||
switch (event.event) {
|
||||
case 'requestCompleted':
|
||||
const p = this.callbacks.fetch((event as Proto.RequestCompletedEvent).body.request_seq);
|
||||
if (p) {
|
||||
p.c(undefined);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'syntaxDiag':
|
||||
case 'semanticDiag':
|
||||
case 'suggestionDiag':
|
||||
|
||||
Reference in New Issue
Block a user