forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
#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
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7675901
Basic tokenizer
eb42669
Fixed property names
2756974
Tests, round I
c2c1ced
Tests, round II
a108c96
merge master
14864a5
tokenizer test
0ed51d6
Remove temorary change
51b544c
Fix merge issue
3cd11e6
Merge conflict
82e0ad1
Merge conflict
9295c1a
Completion test
06eb1a5
Fix last line
e9db8e0
Fix javascript math
d12ca03
Merge master
d8ab041
Make test await for results
db75cd0
Add license headers
9ab2c47
Rename definitions to types
d587485
License headers
1da5e0a
Merge branch 'master' of https://github.com/Microsoft/vscode-python
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
// 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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM, found it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The official link is https://docs.opensource.microsoft.com/releasing/copyright-headers.html