mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 02:58:31 -05:00
Merge VS Code 1.23.1 (#1520)
This commit is contained in:
@@ -9,7 +9,7 @@ import { BracketElectricCharacterSupport, IElectricAction } from 'vs/editor/comm
|
||||
import { IOnEnterSupportOptions, OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter';
|
||||
import { IndentRulesSupport, IndentConsts } from 'vs/editor/common/modes/supports/indentRules';
|
||||
import { RichEditBrackets } from 'vs/editor/common/modes/supports/richEditBrackets';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
@@ -177,8 +177,8 @@ export class LanguageConfigurationRegistryImpl {
|
||||
|
||||
private _entries: RichEditSupport[];
|
||||
|
||||
private _onDidChange: Emitter<LanguageConfigurationChangeEvent> = new Emitter<LanguageConfigurationChangeEvent>();
|
||||
public onDidChange: Event<LanguageConfigurationChangeEvent> = this._onDidChange.event;
|
||||
private readonly _onDidChange: Emitter<LanguageConfigurationChangeEvent> = new Emitter<LanguageConfigurationChangeEvent>();
|
||||
public readonly onDidChange: Event<LanguageConfigurationChangeEvent> = this._onDidChange.event;
|
||||
|
||||
constructor() {
|
||||
this._entries = [];
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { LanguageSelector, score } from 'vs/editor/common/modes/languageSelector';
|
||||
import { shouldSynchronizeModel } from 'vs/editor/common/services/modelService';
|
||||
|
||||
interface Entry<T> {
|
||||
selector: LanguageSelector;
|
||||
@@ -17,11 +18,21 @@ interface Entry<T> {
|
||||
_time: number;
|
||||
}
|
||||
|
||||
function isExclusive(selector: LanguageSelector): boolean {
|
||||
if (typeof selector === 'string') {
|
||||
return false;
|
||||
} else if (Array.isArray(selector)) {
|
||||
return selector.every(isExclusive);
|
||||
} else {
|
||||
return selector.exclusive;
|
||||
}
|
||||
}
|
||||
|
||||
export default class LanguageFeatureRegistry<T> {
|
||||
|
||||
private _clock: number = 0;
|
||||
private _entries: Entry<T>[] = [];
|
||||
private _onDidChange: Emitter<number> = new Emitter<number>();
|
||||
private readonly _onDidChange: Emitter<number> = new Emitter<number>();
|
||||
|
||||
constructor() {
|
||||
}
|
||||
@@ -63,7 +74,7 @@ export default class LanguageFeatureRegistry<T> {
|
||||
}
|
||||
|
||||
all(model: ITextModel): T[] {
|
||||
if (!model || model.isTooLargeForHavingARichMode()) {
|
||||
if (!model) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -106,7 +117,7 @@ export default class LanguageFeatureRegistry<T> {
|
||||
|
||||
private _orderedForEach(model: ITextModel, callback: (provider: Entry<T>) => any): void {
|
||||
|
||||
if (!model || model.isTooLargeForHavingARichMode()) {
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -140,7 +151,17 @@ export default class LanguageFeatureRegistry<T> {
|
||||
this._lastCandidate = candidate;
|
||||
|
||||
for (let entry of this._entries) {
|
||||
entry._score = score(entry.selector, model.uri, model.getLanguageIdentifier().language);
|
||||
entry._score = score(entry.selector, model.uri, model.getLanguageIdentifier().language, shouldSynchronizeModel(model));
|
||||
|
||||
if (isExclusive(entry.selector) && entry._score > 0) {
|
||||
// support for one exclusive selector that overwrites
|
||||
// any other selector
|
||||
for (let entry of this._entries) {
|
||||
entry._score = 0;
|
||||
}
|
||||
entry._score = 1000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// needs sorting
|
||||
|
||||
@@ -12,17 +12,22 @@ export interface LanguageFilter {
|
||||
language?: string;
|
||||
scheme?: string;
|
||||
pattern?: string | IRelativePattern;
|
||||
/**
|
||||
* This provider is implemented in the UI thread.
|
||||
*/
|
||||
hasAccessToAllModels?: boolean;
|
||||
exclusive?: boolean;
|
||||
}
|
||||
|
||||
export type LanguageSelector = string | LanguageFilter | (string | LanguageFilter)[];
|
||||
|
||||
export function score(selector: LanguageSelector, candidateUri: URI, candidateLanguage: string): number {
|
||||
export function score(selector: LanguageSelector, candidateUri: URI, candidateLanguage: string, candidateIsSynchronized: boolean): number {
|
||||
|
||||
if (Array.isArray(selector)) {
|
||||
// array -> take max individual value
|
||||
let ret = 0;
|
||||
for (const filter of selector) {
|
||||
const value = score(filter, candidateUri, candidateLanguage);
|
||||
const value = score(filter, candidateUri, candidateLanguage, candidateIsSynchronized);
|
||||
if (value === 10) {
|
||||
return value; // already at the highest
|
||||
}
|
||||
@@ -33,9 +38,14 @@ export function score(selector: LanguageSelector, candidateUri: URI, candidateLa
|
||||
return ret;
|
||||
|
||||
} else if (typeof selector === 'string') {
|
||||
|
||||
if (!candidateIsSynchronized) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// short-hand notion, desugars to
|
||||
// 'fooLang' -> [{ language: 'fooLang', scheme: 'file' }, { language: 'fooLang', scheme: 'untitled' }]
|
||||
// '*' -> { language: '*', scheme: '*' }
|
||||
// 'fooLang' -> { language: 'fooLang'}
|
||||
// '*' -> { language: '*' }
|
||||
if (selector === '*') {
|
||||
return 5;
|
||||
} else if (selector === candidateLanguage) {
|
||||
@@ -46,7 +56,11 @@ export function score(selector: LanguageSelector, candidateUri: URI, candidateLa
|
||||
|
||||
} else if (selector) {
|
||||
// filter -> select accordingly, use defaults for scheme
|
||||
const { language, pattern, scheme } = selector;
|
||||
const { language, pattern, scheme, hasAccessToAllModels } = selector;
|
||||
|
||||
if (!candidateIsSynchronized && !hasAccessToAllModels) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let ret = 0;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { ILanguageExtensionPoint } from 'vs/editor/common/services/modeService';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
@@ -20,8 +20,8 @@ export class EditorModesRegistry {
|
||||
|
||||
private _languages: ILanguageExtensionPoint[];
|
||||
|
||||
private _onDidAddLanguages: Emitter<ILanguageExtensionPoint[]> = new Emitter<ILanguageExtensionPoint[]>();
|
||||
public onDidAddLanguages: Event<ILanguageExtensionPoint[]> = this._onDidAddLanguages.event;
|
||||
private readonly _onDidAddLanguages: Emitter<ILanguageExtensionPoint[]> = new Emitter<ILanguageExtensionPoint[]>();
|
||||
public readonly onDidAddLanguages: Event<ILanguageExtensionPoint[]> = this._onDidAddLanguages.event;
|
||||
|
||||
constructor() {
|
||||
this._languages = [];
|
||||
|
||||
@@ -85,14 +85,14 @@ function once<T, R>(keyFn: (input: T) => string, computeFn: (input: T) => R): (i
|
||||
const getRegexForBracketPair = once<ISimpleInternalBracket, RegExp>(
|
||||
(input) => `${input.open};${input.close}`,
|
||||
(input) => {
|
||||
return createOrRegex([input.open, input.close]);
|
||||
return createBracketOrRegExp([input.open, input.close]);
|
||||
}
|
||||
);
|
||||
|
||||
const getReversedRegexForBracketPair = once<ISimpleInternalBracket, RegExp>(
|
||||
(input) => `${input.open};${input.close}`,
|
||||
(input) => {
|
||||
return createOrRegex([toReversedString(input.open), toReversedString(input.close)]);
|
||||
return createBracketOrRegExp([toReversedString(input.open), toReversedString(input.close)]);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -104,7 +104,7 @@ const getRegexForBrackets = once<ISimpleInternalBracket[], RegExp>(
|
||||
pieces.push(b.open);
|
||||
pieces.push(b.close);
|
||||
});
|
||||
return createOrRegex(pieces);
|
||||
return createBracketOrRegExp(pieces);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -116,12 +116,19 @@ const getReversedRegexForBrackets = once<ISimpleInternalBracket[], RegExp>(
|
||||
pieces.push(toReversedString(b.open));
|
||||
pieces.push(toReversedString(b.close));
|
||||
});
|
||||
return createOrRegex(pieces);
|
||||
return createBracketOrRegExp(pieces);
|
||||
}
|
||||
);
|
||||
|
||||
function createOrRegex(pieces: string[]): RegExp {
|
||||
let regexStr = `(${pieces.map(strings.escapeRegExpCharacters).join(')|(')})`;
|
||||
function prepareBracketForRegExp(str: string): string {
|
||||
// This bracket pair uses letters like e.g. "begin" - "end"
|
||||
const insertWordBoundaries = (/^[\w]+$/.test(str));
|
||||
str = strings.escapeRegExpCharacters(str);
|
||||
return (insertWordBoundaries ? `\\b${str}\\b` : str);
|
||||
}
|
||||
|
||||
function createBracketOrRegExp(pieces: string[]): RegExp {
|
||||
let regexStr = `(${pieces.map(prepareBracketForRegExp).join(')|(')})`;
|
||||
return strings.createRegExp(regexStr, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { ColorId, ITokenizationRegistry, ITokenizationSupport, ITokenizationSupportChangedEvent } from 'vs/editor/common/modes';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
|
||||
@@ -13,8 +13,8 @@ export class TokenizationRegistryImpl implements ITokenizationRegistry {
|
||||
|
||||
private _map: { [language: string]: ITokenizationSupport };
|
||||
|
||||
private _onDidChange: Emitter<ITokenizationSupportChangedEvent> = new Emitter<ITokenizationSupportChangedEvent>();
|
||||
public onDidChange: Event<ITokenizationSupportChangedEvent> = this._onDidChange.event;
|
||||
private readonly _onDidChange: Emitter<ITokenizationSupportChangedEvent> = new Emitter<ITokenizationSupportChangedEvent>();
|
||||
public readonly onDidChange: Event<ITokenizationSupportChangedEvent> = this._onDidChange.event;
|
||||
|
||||
private _colorMap: Color[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user