Skip to content

#34, #110 - suppress Intellisense in strings and comments #339

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

Merged
merged 19 commits into from
Dec 5, 2017
1,107 changes: 100 additions & 1,007 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,7 @@
"semver": "^5.4.1",
"tmp": "0.0.29",
"tree-kill": "^1.1.0",
"typescript-char": "^0.0.0",
"uint64be": "^1.0.1",
"untildify": "^3.0.2",
"vscode-debugadapter": "^1.0.1",
Expand Down
15 changes: 11 additions & 4 deletions src/client/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const tmp = require('tmp');

export function isNotInstalledError(error: Error): boolean {
const isError = typeof (error) === 'object' && error !== null;
// tslint:disable-next-line:no-any
const errorObj = <any>error;
if (!isError) {
return false;
Expand All @@ -11,20 +12,23 @@ export function isNotInstalledError(error: Error): boolean {
}

export interface Deferred<T> {
resolve(value?: T | PromiseLike<T>);
reject(reason?: any);
readonly promise: Promise<T>;
readonly resolved: boolean;
readonly rejected: boolean;
readonly completed: boolean;
resolve(value?: T | PromiseLike<T>);
// tslint:disable-next-line:no-any
reject(reason?: any);
}

class DeferredImpl<T> implements Deferred<T> {
private _resolve: (value?: T | PromiseLike<T>) => void;
// tslint:disable-next-line:no-any
private _reject: (reason?: any) => void;
private _resolved: boolean = false;
private _rejected: boolean = false;
private _promise: Promise<T>;
// tslint:disable-next-line:no-any
constructor(private scope: any = null) {
// tslint:disable-next-line:promise-must-complete
this._promise = new Promise<T>((res, rej) => {
Expand All @@ -36,6 +40,7 @@ class DeferredImpl<T> implements Deferred<T> {
this._resolve.apply(this.scope ? this.scope : this, arguments);
this._resolved = true;
}
// tslint:disable-next-line:no-any
reject(reason?: any) {
this._reject.apply(this.scope ? this.scope : this, arguments);
this._rejected = true;
Expand All @@ -53,12 +58,14 @@ class DeferredImpl<T> implements Deferred<T> {
return this._rejected || this._resolved;
}
}
export function createDeferred<T>(scope: any = null): Deferred<T> {
// tslint:disable-next-line:no-any
export function createDeferred<T>(scope: any = null): Deferred<T> {
return new DeferredImpl<T>(scope);
}

export function createTemporaryFile(extension: string, temporaryDirectory?: string): Promise<{ filePath: string, cleanupCallback: Function }> {
let options: any = { postfix: extension };
// tslint:disable-next-line:no-any
const options: any = { postfix: extension };
if (temporaryDirectory) {
options.dir = temporaryDirectory;
}
Expand Down
133 changes: 133 additions & 0 deletions src/client/language/characterStream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Microsoft license header to all new files.
Also please remove use strict (not necessary)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find the license header sample, where is the template

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM, found it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// tslint:disable-next-line:import-name
import Char from 'typescript-char';
import { TextIterator } from './textIterator';
import { ICharacterStream, ITextIterator } from './types';

export class CharacterStream implements ICharacterStream {
private text: ITextIterator;
private _position: number;
private _currentChar: number;
private _isEndOfStream: boolean;

constructor(text: string | ITextIterator) {
this.text = typeof text === 'string' ? new TextIterator(text) : text;
this._position = 0;
this._currentChar = text.length > 0 ? text.charCodeAt(0) : 0;
this._isEndOfStream = text.length === 0;
}

public getText(): string {
return this.text.getText();
}

public get position(): number {
return this._position;
}

public set position(value: number) {
this._position = value;
this.checkBounds();
}

public get currentChar(): number {
return this._currentChar;
}

public get nextChar(): number {
return this.position + 1 < this.text.length ? this.text.charCodeAt(this.position + 1) : 0;
}

public get prevChar(): number {
return this.position - 1 >= 0 ? this.text.charCodeAt(this.position - 1) : 0;
}

public isEndOfStream(): boolean {
return this._isEndOfStream;
}

public lookAhead(offset: number): number {
const pos = this._position + offset;
return pos < 0 || pos >= this.text.length ? 0 : this.text.charCodeAt(pos);
}

public advance(offset: number) {
this.position += offset;
}

public moveNext(): boolean {
if (this._position < this.text.length - 1) {
// Most common case, no need to check bounds extensively
this._position += 1;
this._currentChar = this.text.charCodeAt(this._position);
return true;
}
this.advance(1);
return !this.isEndOfStream();
}

public isAtWhiteSpace(): boolean {
return this.currentChar <= Char.Space || this.currentChar === 0x200B; // Unicode whitespace
}

public isAtLineBreak(): boolean {
return this.currentChar === Char.CarriageReturn || this.currentChar === Char.LineFeed;
}

public skipLineBreak(): void {
if (this._currentChar === Char.CarriageReturn) {
this.moveNext();
if (this.currentChar === Char.LineFeed) {
this.moveNext();
}
} else if (this._currentChar === Char.LineFeed) {
this.moveNext();
}
}

public skipWhitespace(): void {
while (!this.isEndOfStream() && this.isAtWhiteSpace()) {
this.moveNext();
}
}

public skipToEol(): void {
while (!this.isEndOfStream() && !this.isAtLineBreak()) {
this.moveNext();
}
}

public skipToWhitespace(): void {
while (!this.isEndOfStream() && !this.isAtWhiteSpace()) {
this.moveNext();
}
}

public isAtString(): boolean {
return this.currentChar === Char.SingleQuote || this.currentChar === Char.DoubleQuote;
}

public charCodeAt(index: number): number {
return this.text.charCodeAt(index);
}

public get length(): number {
return this.text.length;
}

private checkBounds(): void {
if (this._position < 0) {
this._position = 0;
}

this._isEndOfStream = this._position >= this.text.length;
if (this._isEndOfStream) {
this._position = this.text.length;
}

this._currentChar = this._isEndOfStream ? 0 : this.text.charCodeAt(this._position);
}
}
55 changes: 55 additions & 0 deletions src/client/language/textIterator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

import { Position, Range, TextDocument } from 'vscode';
import { ITextIterator } from './types';

export class TextIterator implements ITextIterator {
private text: string;

constructor(text: string) {
this.text = text;
}

public charCodeAt(index: number): number {
if (index >= 0 && index < this.text.length) {
return this.text.charCodeAt(index);
}
return 0;
}

public get length(): number {
return this.text.length;
}

public getText(): string {
return this.text;
}
}

export class DocumentTextIterator implements ITextIterator {
public readonly length: number;

private document: TextDocument;

constructor(document: TextDocument) {
this.document = document;

const lastIndex = this.document.lineCount - 1;
const lastLine = this.document.lineAt(lastIndex);
const end = new Position(lastIndex, lastLine.range.end.character);
this.length = this.document.offsetAt(end);
}

public charCodeAt(index: number): number {
const position = this.document.positionAt(index);
return this.document
.getText(new Range(position, position.translate(0, 1)))
.charCodeAt(position.character);
}

public getText(): string {
return this.document.getText();
}
}
105 changes: 105 additions & 0 deletions src/client/language/textRangeCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';

import { ITextRange, ITextRangeCollection } from './types';

export class TextRangeCollection<T extends ITextRange> implements ITextRangeCollection<T> {
private items: T[];

constructor(items: T[]) {
this.items = items;
}

public get start(): number {
return this.items.length > 0 ? this.items[0].start : 0;
}

public get end(): number {
return this.items.length > 0 ? this.items[this.items.length - 1].end : 0;
}

public get length(): number {
return this.end - this.start;
}

public get count(): number {
return this.items.length;
}

public contains(position: number) {
return position >= this.start && position < this.end;
}

public getItemAt(index: number): T {
if (index < 0 || index >= this.items.length) {
throw new Error('index is out of range');
}
return this.items[index] as T;
}

public getItemAtPosition(position: number): number {
if (this.count === 0) {
return -1;
}
if (position < this.start) {
return -1;
}
if (position >= this.end) {
return -1;
}

let min = 0;
let max = this.count - 1;

while (min <= max) {
const mid = Math.floor(min + (max - min) / 2);
const item = this.items[mid];

if (item.start === position) {
return mid;
}

if (position < item.start) {
max = mid - 1;
} else {
min = mid + 1;
}
}
return -1;
}

public getItemContaining(position: number): number {
if (this.count === 0) {
return -1;
}
if (position < this.start) {
return -1;
}
if (position > this.end) {
return -1;
}

let min = 0;
let max = this.count - 1;

while (min <= max) {
const mid = Math.floor(min + (max - min) / 2);
const item = this.items[mid];

if (item.contains(position)) {
return mid;
}
if (mid < this.count - 1 && item.end <= position && position < this.items[mid + 1].start) {
return -1;
}

if (position < item.start) {
max = mid - 1;
} else {
min = mid + 1;
}
}
return -1;
}
}
Loading