mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 18:46:36 -05:00
Merge VS Code 1.23.1 (#1520)
This commit is contained in:
@@ -22,6 +22,7 @@ import { getWordAtText, ensureValidWordDefinition } from 'vs/editor/common/model
|
||||
import { createMonacoBaseAPI } from 'vs/editor/common/standalone/standaloneBase';
|
||||
import { IWordAtPosition, EndOfLineSequence } from 'vs/editor/common/model';
|
||||
import { globals } from 'vs/base/common/platform';
|
||||
import { IIterator } from 'vs/base/common/iterator';
|
||||
|
||||
export interface IMirrorModel {
|
||||
readonly uri: URI;
|
||||
@@ -58,8 +59,8 @@ export interface ICommonModel {
|
||||
getLinesContent(): string[];
|
||||
getLineCount(): number;
|
||||
getLineContent(lineNumber: number): string;
|
||||
createWordIterator(wordDefinition: RegExp): IIterator<string>;
|
||||
getWordUntilPosition(position: IPosition, wordDefinition: RegExp): IWordAtPosition;
|
||||
getAllUniqueWords(wordDefinition: RegExp, skipWordOnce?: string): string[];
|
||||
getValueInRange(range: IRange): string;
|
||||
getWordAtPosition(position: IPosition, wordDefinition: RegExp): Range;
|
||||
offsetAt(position: IPosition): number;
|
||||
@@ -146,30 +147,37 @@ class MirrorModel extends BaseMirrorModel implements ICommonModel {
|
||||
};
|
||||
}
|
||||
|
||||
private _getAllWords(wordDefinition: RegExp): string[] {
|
||||
let result: string[] = [];
|
||||
this._lines.forEach((line) => {
|
||||
this._wordenize(line, wordDefinition).forEach((info) => {
|
||||
result.push(line.substring(info.start, info.end));
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
public createWordIterator(wordDefinition: RegExp): IIterator<string> {
|
||||
let obj = {
|
||||
done: false,
|
||||
value: ''
|
||||
};
|
||||
let lineNumber = 0;
|
||||
let lineText: string;
|
||||
let wordRangesIdx = 0;
|
||||
let wordRanges: IWordRange[] = [];
|
||||
let next = () => {
|
||||
|
||||
if (wordRangesIdx < wordRanges.length) {
|
||||
obj.done = false;
|
||||
obj.value = lineText.substring(wordRanges[wordRangesIdx].start, wordRanges[wordRangesIdx].end);
|
||||
wordRangesIdx += 1;
|
||||
|
||||
} else if (lineNumber >= this._lines.length) {
|
||||
obj.done = true;
|
||||
obj.value = undefined;
|
||||
|
||||
public getAllUniqueWords(wordDefinition: RegExp, skipWordOnce?: string): string[] {
|
||||
let foundSkipWord = false;
|
||||
let uniqueWords = Object.create(null);
|
||||
return this._getAllWords(wordDefinition).filter((word) => {
|
||||
if (skipWordOnce && !foundSkipWord && skipWordOnce === word) {
|
||||
foundSkipWord = true;
|
||||
return false;
|
||||
} else if (uniqueWords[word]) {
|
||||
return false;
|
||||
} else {
|
||||
uniqueWords[word] = true;
|
||||
return true;
|
||||
lineText = this._lines[lineNumber];
|
||||
wordRanges = this._wordenize(lineText, wordDefinition);
|
||||
wordRangesIdx = 0;
|
||||
lineNumber += 1;
|
||||
return next();
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
return { next };
|
||||
}
|
||||
|
||||
private _wordenize(content: string, wordDefinition: RegExp): IWordRange[] {
|
||||
@@ -288,13 +296,24 @@ class MirrorModel extends BaseMirrorModel implements ICommonModel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface IForeignModuleFactory {
|
||||
(ctx: IWorkerContext, createData: any): any;
|
||||
}
|
||||
|
||||
declare var require;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export abstract class BaseEditorSimpleWorker {
|
||||
private _foreignModuleFactory: IForeignModuleFactory;
|
||||
private _foreignModule: any;
|
||||
|
||||
constructor() {
|
||||
constructor(foreignModuleFactory: IForeignModuleFactory) {
|
||||
this._foreignModuleFactory = foreignModuleFactory;
|
||||
this._foreignModule = null;
|
||||
}
|
||||
|
||||
@@ -416,6 +435,8 @@ export abstract class BaseEditorSimpleWorker {
|
||||
|
||||
// ---- BEGIN suggest --------------------------------------------------------------------------
|
||||
|
||||
private static readonly _suggestionsLimit = 10000;
|
||||
|
||||
public textualSuggest(modelUrl: string, position: IPosition, wordDef: string, wordDefFlags: string): TPromise<ISuggestResult> {
|
||||
const model = this._getModel(modelUrl);
|
||||
if (model) {
|
||||
@@ -423,17 +444,32 @@ export abstract class BaseEditorSimpleWorker {
|
||||
const wordDefRegExp = new RegExp(wordDef, wordDefFlags);
|
||||
const currentWord = model.getWordUntilPosition(position, wordDefRegExp).word;
|
||||
|
||||
for (const word of model.getAllUniqueWords(wordDefRegExp)) {
|
||||
if (word !== currentWord && isNaN(Number(word))) {
|
||||
suggestions.push({
|
||||
type: 'text',
|
||||
label: word,
|
||||
insertText: word,
|
||||
noAutoAccept: true,
|
||||
overwriteBefore: currentWord.length
|
||||
});
|
||||
const seen: Record<string, boolean> = Object.create(null);
|
||||
seen[currentWord] = true;
|
||||
|
||||
for (
|
||||
let iter = model.createWordIterator(wordDefRegExp), e = iter.next();
|
||||
!e.done && suggestions.length <= BaseEditorSimpleWorker._suggestionsLimit;
|
||||
e = iter.next()
|
||||
) {
|
||||
const word = e.value;
|
||||
if (seen[word]) {
|
||||
continue;
|
||||
}
|
||||
seen[word] = true;
|
||||
if (!isNaN(Number(word))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
suggestions.push({
|
||||
type: 'text',
|
||||
label: word,
|
||||
insertText: word,
|
||||
noAutoAccept: true,
|
||||
overwriteBefore: currentWord.length
|
||||
});
|
||||
}
|
||||
|
||||
return TPromise.as({ suggestions });
|
||||
}
|
||||
return undefined;
|
||||
@@ -474,14 +510,25 @@ export abstract class BaseEditorSimpleWorker {
|
||||
// ---- BEGIN foreign module support --------------------------------------------------------------------------
|
||||
|
||||
public loadForeignModule(moduleId: string, createData: any): TPromise<string[]> {
|
||||
let ctx: IWorkerContext = {
|
||||
getMirrorModels: (): IMirrorModel[] => {
|
||||
return this._getModels();
|
||||
}
|
||||
};
|
||||
|
||||
if (this._foreignModuleFactory) {
|
||||
this._foreignModule = this._foreignModuleFactory(ctx, createData);
|
||||
// static foreing module
|
||||
let methods: string[] = [];
|
||||
for (let prop in this._foreignModule) {
|
||||
if (typeof this._foreignModule[prop] === 'function') {
|
||||
methods.push(prop);
|
||||
}
|
||||
}
|
||||
return TPromise.as(methods);
|
||||
}
|
||||
return new TPromise<any>((c, e) => {
|
||||
// Use the global require to be sure to get the global config
|
||||
(<any>self).require([moduleId], (foreignModule: { create: (ctx: IWorkerContext, createData: any) => any; }) => {
|
||||
let ctx: IWorkerContext = {
|
||||
getMirrorModels: (): IMirrorModel[] => {
|
||||
return this._getModels();
|
||||
}
|
||||
};
|
||||
require([moduleId], (foreignModule: { create: IForeignModuleFactory }) => {
|
||||
this._foreignModule = foreignModule.create(ctx, createData);
|
||||
|
||||
let methods: string[] = [];
|
||||
@@ -521,8 +568,8 @@ export class EditorSimpleWorkerImpl extends BaseEditorSimpleWorker implements IR
|
||||
|
||||
private _models: { [uri: string]: MirrorModel; };
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
constructor(foreignModuleFactory: IForeignModuleFactory) {
|
||||
super(foreignModuleFactory);
|
||||
this._models = Object.create(null);
|
||||
}
|
||||
|
||||
@@ -565,9 +612,12 @@ export class EditorSimpleWorkerImpl extends BaseEditorSimpleWorker implements IR
|
||||
* @internal
|
||||
*/
|
||||
export function create(): IRequestHandler {
|
||||
return new EditorSimpleWorkerImpl();
|
||||
return new EditorSimpleWorkerImpl(null);
|
||||
}
|
||||
|
||||
// This is only available in a Web Worker
|
||||
declare function importScripts(...urls: string[]): void;
|
||||
|
||||
if (typeof importScripts === 'function') {
|
||||
// Running in a web worker
|
||||
globals.monaco = createMonacoBaseAPI();
|
||||
|
||||
@@ -351,7 +351,7 @@ export class EditorWorkerClient extends Disposable {
|
||||
));
|
||||
} catch (err) {
|
||||
logOnceWebWorkerWarning(err);
|
||||
this._worker = new SynchronousWorkerClient(new EditorSimpleWorkerImpl());
|
||||
this._worker = new SynchronousWorkerClient(new EditorSimpleWorkerImpl(null));
|
||||
}
|
||||
}
|
||||
return this._worker;
|
||||
@@ -360,7 +360,7 @@ export class EditorWorkerClient extends Disposable {
|
||||
protected _getProxy(): TPromise<EditorSimpleWorkerImpl> {
|
||||
return new ShallowCancelThenPromise(this._getOrCreateWorker().getProxyObject().then(null, (err) => {
|
||||
logOnceWebWorkerWarning(err);
|
||||
this._worker = new SynchronousWorkerClient(new EditorSimpleWorkerImpl());
|
||||
this._worker = new SynchronousWorkerClient(new EditorSimpleWorkerImpl(null));
|
||||
return this._getOrCreateWorker().getProxyObject();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -111,13 +111,9 @@ export class LanguagesRegistry {
|
||||
|
||||
let primaryMime: string = null;
|
||||
|
||||
if (typeof lang.mimetypes !== 'undefined' && Array.isArray(lang.mimetypes)) {
|
||||
for (let i = 0; i < lang.mimetypes.length; i++) {
|
||||
if (!primaryMime) {
|
||||
primaryMime = lang.mimetypes[i];
|
||||
}
|
||||
resolvedLanguage.mimetypes.push(lang.mimetypes[i]);
|
||||
}
|
||||
if (Array.isArray(lang.mimetypes) && lang.mimetypes.length > 0) {
|
||||
resolvedLanguage.mimetypes.push(...lang.mimetypes);
|
||||
primaryMime = lang.mimetypes[0];
|
||||
}
|
||||
|
||||
if (!primaryMime) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import Event from 'vs/base/common/event';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { FrankensteinMode } from 'vs/editor/common/modes/abstractMode';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import Event from 'vs/base/common/event';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -16,7 +16,7 @@ export const IModelService = createDecorator<IModelService>('modelService');
|
||||
export interface IModelService {
|
||||
_serviceBrand: any;
|
||||
|
||||
createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI): ITextModel;
|
||||
createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI, isForSimpleWidget?: boolean): ITextModel;
|
||||
|
||||
updateModel(model: ITextModel, value: string | ITextBufferFactory): void;
|
||||
|
||||
@@ -26,7 +26,7 @@ export interface IModelService {
|
||||
|
||||
getModels(): ITextModel[];
|
||||
|
||||
getCreationOptions(language: string, resource: URI): ITextModelCreationOptions;
|
||||
getCreationOptions(language: string, resource: URI, isForSimpleWidget: boolean): ITextModelCreationOptions;
|
||||
|
||||
getModel(resource: URI): ITextModel;
|
||||
|
||||
@@ -36,3 +36,9 @@ export interface IModelService {
|
||||
|
||||
onModelModeChanged: Event<{ model: ITextModel; oldModeId: string; }>;
|
||||
}
|
||||
|
||||
export function shouldSynchronizeModel(model: ITextModel): boolean {
|
||||
return (
|
||||
!model.isTooLargeForSyncing() && !model.isForSimpleWidget
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,14 @@
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import network = require('vs/base/common/network');
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import * as network from 'vs/base/common/network';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { MarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IMarker, IMarkerService } from 'vs/platform/markers/common/markers';
|
||||
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { TextModel, createTextBuffer } from 'vs/editor/common/model/textModel';
|
||||
import { IMode, LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
@@ -28,6 +26,8 @@ import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { themeColorFromId, ThemeColor } from 'vs/platform/theme/common/themeService';
|
||||
import { overviewRulerWarning, overviewRulerError, overviewRulerInfo } from 'vs/editor/common/view/editorColorRegistry';
|
||||
import { ITextModel, IModelDeltaDecoration, IModelDecorationOptions, TrackedRangeStickiness, OverviewRulerLane, DefaultEndOfLine, ITextModelCreationOptions, EndOfLineSequence, IIdentifiedSingleEditOperation, ITextBufferFactory, ITextBuffer, EndOfLinePreference } from 'vs/editor/common/model';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import { basename } from 'vs/base/common/paths';
|
||||
|
||||
function MODEL_ID(resource: URI): string {
|
||||
return resource.toString();
|
||||
@@ -82,15 +82,23 @@ class ModelMarkerHandler {
|
||||
}
|
||||
|
||||
private static _createDecorationRange(model: ITextModel, rawMarker: IMarker): Range {
|
||||
let marker = model.validateRange(new Range(rawMarker.startLineNumber, rawMarker.startColumn, rawMarker.endLineNumber, rawMarker.endColumn));
|
||||
let ret: Range = new Range(marker.startLineNumber, marker.startColumn, marker.endLineNumber, marker.endColumn);
|
||||
|
||||
let ret = Range.lift(rawMarker);
|
||||
|
||||
if (rawMarker.severity === MarkerSeverity.Hint && Range.spansMultipleLines(ret)) {
|
||||
// never render hints on multiple lines
|
||||
ret = ret.setEndPosition(ret.startLineNumber, ret.startColumn);
|
||||
}
|
||||
|
||||
ret = model.validateRange(ret);
|
||||
|
||||
if (ret.isEmpty()) {
|
||||
let word = model.getWordAtPosition(ret.getStartPosition());
|
||||
if (word) {
|
||||
ret = new Range(ret.startLineNumber, word.startColumn, ret.endLineNumber, word.endColumn);
|
||||
} else {
|
||||
let maxColumn = model.getLineLastNonWhitespaceColumn(marker.startLineNumber) ||
|
||||
model.getLineMaxColumn(marker.startLineNumber);
|
||||
let maxColumn = model.getLineLastNonWhitespaceColumn(ret.startLineNumber) ||
|
||||
model.getLineMaxColumn(ret.startLineNumber);
|
||||
|
||||
if (maxColumn === 1) {
|
||||
// empty line
|
||||
@@ -118,31 +126,36 @@ class ModelMarkerHandler {
|
||||
let className: string;
|
||||
let color: ThemeColor;
|
||||
let darkColor: ThemeColor;
|
||||
let zIndex: number;
|
||||
|
||||
switch (marker.severity) {
|
||||
case Severity.Ignore:
|
||||
// do something
|
||||
case MarkerSeverity.Hint:
|
||||
className = ClassName.EditorHintDecoration;
|
||||
zIndex = 0;
|
||||
break;
|
||||
case Severity.Warning:
|
||||
case MarkerSeverity.Warning:
|
||||
className = ClassName.EditorWarningDecoration;
|
||||
color = themeColorFromId(overviewRulerWarning);
|
||||
darkColor = themeColorFromId(overviewRulerWarning);
|
||||
zIndex = 20;
|
||||
break;
|
||||
case Severity.Info:
|
||||
case MarkerSeverity.Info:
|
||||
className = ClassName.EditorInfoDecoration;
|
||||
color = themeColorFromId(overviewRulerInfo);
|
||||
darkColor = themeColorFromId(overviewRulerInfo);
|
||||
zIndex = 10;
|
||||
break;
|
||||
case Severity.Error:
|
||||
case MarkerSeverity.Error:
|
||||
default:
|
||||
className = ClassName.EditorErrorDecoration;
|
||||
color = themeColorFromId(overviewRulerError);
|
||||
darkColor = themeColorFromId(overviewRulerError);
|
||||
zIndex = 30;
|
||||
break;
|
||||
}
|
||||
|
||||
let hoverMessage: MarkdownString = null;
|
||||
let { message, source } = marker;
|
||||
let { message, source, relatedInformation } = marker;
|
||||
|
||||
if (typeof message === 'string') {
|
||||
message = message.trim();
|
||||
@@ -156,6 +169,16 @@ class ModelMarkerHandler {
|
||||
}
|
||||
|
||||
hoverMessage = new MarkdownString().appendCodeblock('_', message);
|
||||
|
||||
if (!isFalsyOrEmpty(relatedInformation)) {
|
||||
hoverMessage.appendMarkdown('\n');
|
||||
for (const { message, resource, startLineNumber, startColumn } of relatedInformation) {
|
||||
hoverMessage.appendMarkdown(
|
||||
`* [${basename(resource.path)}(${startLineNumber}, ${startColumn})](${resource.toString(false)}#${startLineNumber},${startColumn}): \`${message}\` \n`
|
||||
);
|
||||
}
|
||||
hoverMessage.appendMarkdown('\n');
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -167,7 +190,8 @@ class ModelMarkerHandler {
|
||||
color,
|
||||
darkColor,
|
||||
position: OverviewRulerLane.Right
|
||||
}
|
||||
},
|
||||
zIndex
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -181,6 +205,8 @@ interface IRawConfig {
|
||||
insertSpaces?: any;
|
||||
detectIndentation?: any;
|
||||
trimAutoWhitespace?: any;
|
||||
creationOptions?: any;
|
||||
largeFileOptimizations?: any;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -194,9 +220,9 @@ export class ModelServiceImpl implements IModelService {
|
||||
private _configurationService: IConfigurationService;
|
||||
private _configurationServiceSubscription: IDisposable;
|
||||
|
||||
private _onModelAdded: Emitter<ITextModel>;
|
||||
private _onModelRemoved: Emitter<ITextModel>;
|
||||
private _onModelModeChanged: Emitter<{ model: ITextModel; oldModeId: string; }>;
|
||||
private readonly _onModelAdded: Emitter<ITextModel>;
|
||||
private readonly _onModelRemoved: Emitter<ITextModel>;
|
||||
private readonly _onModelModeChanged: Emitter<{ model: ITextModel; oldModeId: string; }>;
|
||||
|
||||
private _modelCreationOptionsByLanguageAndResource: {
|
||||
[languageAndResource: string]: ITextModelCreationOptions;
|
||||
@@ -227,7 +253,7 @@ export class ModelServiceImpl implements IModelService {
|
||||
this._updateModelOptions();
|
||||
}
|
||||
|
||||
private static _readModelOptions(config: IRawConfig): ITextModelCreationOptions {
|
||||
private static _readModelOptions(config: IRawConfig, isForSimpleWidget: boolean): ITextModelCreationOptions {
|
||||
let tabSize = EDITOR_MODEL_DEFAULTS.tabSize;
|
||||
if (config.editor && typeof config.editor.tabSize !== 'undefined') {
|
||||
let parsedTabSize = parseInt(config.editor.tabSize, 10);
|
||||
@@ -259,19 +285,26 @@ export class ModelServiceImpl implements IModelService {
|
||||
detectIndentation = (config.editor.detectIndentation === 'false' ? false : Boolean(config.editor.detectIndentation));
|
||||
}
|
||||
|
||||
let largeFileOptimizations = EDITOR_MODEL_DEFAULTS.largeFileOptimizations;
|
||||
if (config.editor && typeof config.editor.largeFileOptimizations !== 'undefined') {
|
||||
largeFileOptimizations = (config.editor.largeFileOptimizations === 'false' ? false : Boolean(config.editor.largeFileOptimizations));
|
||||
}
|
||||
|
||||
return {
|
||||
isForSimpleWidget: isForSimpleWidget,
|
||||
tabSize: tabSize,
|
||||
insertSpaces: insertSpaces,
|
||||
detectIndentation: detectIndentation,
|
||||
defaultEOL: newDefaultEOL,
|
||||
trimAutoWhitespace: trimAutoWhitespace
|
||||
trimAutoWhitespace: trimAutoWhitespace,
|
||||
largeFileOptimizations: largeFileOptimizations
|
||||
};
|
||||
}
|
||||
|
||||
public getCreationOptions(language: string, resource: URI): ITextModelCreationOptions {
|
||||
public getCreationOptions(language: string, resource: URI, isForSimpleWidget: boolean): ITextModelCreationOptions {
|
||||
let creationOptions = this._modelCreationOptionsByLanguageAndResource[language + resource];
|
||||
if (!creationOptions) {
|
||||
creationOptions = ModelServiceImpl._readModelOptions(this._configurationService.getValue({ overrideIdentifier: language, resource }));
|
||||
creationOptions = ModelServiceImpl._readModelOptions(this._configurationService.getValue({ overrideIdentifier: language, resource }), isForSimpleWidget);
|
||||
this._modelCreationOptionsByLanguageAndResource[language + resource] = creationOptions;
|
||||
}
|
||||
return creationOptions;
|
||||
@@ -289,7 +322,7 @@ export class ModelServiceImpl implements IModelService {
|
||||
const language = modelData.model.getLanguageIdentifier().language;
|
||||
const uri = modelData.model.uri;
|
||||
const oldOptions = oldOptionsByLanguageAndResource[language + uri];
|
||||
const newOptions = this.getCreationOptions(language, uri);
|
||||
const newOptions = this.getCreationOptions(language, uri, modelData.model.isForSimpleWidget);
|
||||
ModelServiceImpl._setModelOptionsForModel(modelData.model, newOptions, oldOptions);
|
||||
}
|
||||
}
|
||||
@@ -353,9 +386,9 @@ export class ModelServiceImpl implements IModelService {
|
||||
|
||||
// --- begin IModelService
|
||||
|
||||
private _createModelData(value: string | ITextBufferFactory, languageIdentifier: LanguageIdentifier, resource: URI): ModelData {
|
||||
private _createModelData(value: string | ITextBufferFactory, languageIdentifier: LanguageIdentifier, resource: URI, isForSimpleWidget: boolean): ModelData {
|
||||
// create & save the model
|
||||
const options = this.getCreationOptions(languageIdentifier.language, resource);
|
||||
const options = this.getCreationOptions(languageIdentifier.language, resource, isForSimpleWidget);
|
||||
const model: TextModel = new TextModel(value, options, languageIdentifier, resource);
|
||||
const modelId = MODEL_ID(model.uri);
|
||||
|
||||
@@ -375,7 +408,7 @@ export class ModelServiceImpl implements IModelService {
|
||||
}
|
||||
|
||||
public updateModel(model: ITextModel, value: string | ITextBufferFactory): void {
|
||||
const options = this.getCreationOptions(model.getLanguageIdentifier().language, model.uri);
|
||||
const options = this.getCreationOptions(model.getLanguageIdentifier().language, model.uri, model.isForSimpleWidget);
|
||||
const textBuffer = createTextBuffer(value, options.defaultEOL);
|
||||
|
||||
// Return early if the text is already set in that form
|
||||
@@ -384,12 +417,14 @@ export class ModelServiceImpl implements IModelService {
|
||||
}
|
||||
|
||||
// Otherwise find a diff between the values and update model
|
||||
model.pushStackElement();
|
||||
model.setEOL(textBuffer.getEOL() === '\r\n' ? EndOfLineSequence.CRLF : EndOfLineSequence.LF);
|
||||
model.pushEditOperations(
|
||||
[new Selection(1, 1, 1, 1)],
|
||||
[],
|
||||
ModelServiceImpl._computeEdits(model, textBuffer),
|
||||
(inverseEditOperations: IIdentifiedSingleEditOperation[]) => [new Selection(1, 1, 1, 1)]
|
||||
(inverseEditOperations: IIdentifiedSingleEditOperation[]) => []
|
||||
);
|
||||
model.pushStackElement();
|
||||
}
|
||||
|
||||
private static _commonPrefix(a: ILineSequence, aLen: number, aDelta: number, b: ILineSequence, bLen: number, bDelta: number): number {
|
||||
@@ -439,17 +474,17 @@ export class ModelServiceImpl implements IModelService {
|
||||
newRange = new Range(1, 1, textBufferLineCount, 1 + textBuffer.getLineLength(textBufferLineCount));
|
||||
}
|
||||
|
||||
return [EditOperation.replace(oldRange, textBuffer.getValueInRange(newRange, EndOfLinePreference.TextDefined))];
|
||||
return [EditOperation.replaceMove(oldRange, textBuffer.getValueInRange(newRange, EndOfLinePreference.TextDefined))];
|
||||
}
|
||||
|
||||
public createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI): ITextModel {
|
||||
public createModel(value: string | ITextBufferFactory, modeOrPromise: TPromise<IMode> | IMode, resource: URI, isForSimpleWidget: boolean = false): ITextModel {
|
||||
let modelData: ModelData;
|
||||
|
||||
if (!modeOrPromise || TPromise.is(modeOrPromise)) {
|
||||
modelData = this._createModelData(value, PLAINTEXT_LANGUAGE_IDENTIFIER, resource);
|
||||
modelData = this._createModelData(value, PLAINTEXT_LANGUAGE_IDENTIFIER, resource, isForSimpleWidget);
|
||||
this.setMode(modelData.model, modeOrPromise);
|
||||
} else {
|
||||
modelData = this._createModelData(value, modeOrPromise.getLanguageIdentifier(), resource);
|
||||
modelData = this._createModelData(value, modeOrPromise.getLanguageIdentifier(), resource, isForSimpleWidget);
|
||||
}
|
||||
|
||||
// handle markers (marker service => model)
|
||||
@@ -535,8 +570,8 @@ export class ModelServiceImpl implements IModelService {
|
||||
private _onDidChangeLanguage(model: ITextModel, e: IModelLanguageChangedEvent): void {
|
||||
const oldModeId = e.oldLanguage;
|
||||
const newModeId = model.getLanguageIdentifier().language;
|
||||
const oldOptions = this.getCreationOptions(oldModeId, model.uri);
|
||||
const newOptions = this.getCreationOptions(newModeId, model.uri);
|
||||
const oldOptions = this.getCreationOptions(oldModeId, model.uri, model.isForSimpleWidget);
|
||||
const newOptions = this.getCreationOptions(newModeId, model.uri, model.isForSimpleWidget);
|
||||
ModelServiceImpl._setModelOptionsForModel(model, newOptions, oldOptions);
|
||||
this._onModelModeChanged.fire({ model, oldModeId });
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import Event from 'vs/base/common/event';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
|
||||
@@ -11,6 +11,7 @@ import { ITextResourceConfigurationService } from 'vs/editor/common/services/res
|
||||
import { IPosition, Position } from 'vs/editor/common/core/position';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { basename } from 'vs/base/common/paths';
|
||||
|
||||
export class TextResourceConfigurationService extends Disposable implements ITextResourceConfigurationService {
|
||||
|
||||
@@ -42,6 +43,6 @@ export class TextResourceConfigurationService extends Disposable implements ITex
|
||||
if (model) {
|
||||
return position ? this.modeService.getLanguageIdentifier(model.getLanguageIdAtPosition(position.lineNumber, position.column)).language : model.getLanguageIdentifier().language;
|
||||
}
|
||||
return this.modeService.getModeIdByFilenameOrFirstLine(resource.fsPath);
|
||||
return this.modeService.getModeIdByFilenameOrFirstLine(basename(resource.path));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user