vscode-languageserver-textdocument
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -32,3 +32,3 @@ /* -------------------------------------------------------------------------------------------- | ||
update(changes, version) { | ||
for (let change of changes) { | ||
for (const change of changes) { | ||
if (FullTextDocument.isIncremental(change)) { | ||
@@ -84,3 +84,3 @@ // makes sure start is before end | ||
offset = Math.max(Math.min(offset, this._content.length), 0); | ||
let lineOffsets = this.getLineOffsets(); | ||
const lineOffsets = this.getLineOffsets(); | ||
let low = 0, high = lineOffsets.length; | ||
@@ -91,3 +91,3 @@ if (high === 0) { | ||
while (low < high) { | ||
let mid = Math.floor((low + high) / 2); | ||
const mid = Math.floor((low + high) / 2); | ||
if (lineOffsets[mid] > offset) { | ||
@@ -102,7 +102,8 @@ high = mid; | ||
// or array.length if no line offset is larger than the current offset | ||
let line = low - 1; | ||
const line = low - 1; | ||
offset = this.ensureBeforeEOL(offset, lineOffsets[line]); | ||
return { line, character: offset - lineOffsets[line] }; | ||
} | ||
offsetAt(position) { | ||
let lineOffsets = this.getLineOffsets(); | ||
const lineOffsets = this.getLineOffsets(); | ||
if (position.line >= lineOffsets.length) { | ||
@@ -114,6 +115,16 @@ return this._content.length; | ||
} | ||
let lineOffset = lineOffsets[position.line]; | ||
let nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length; | ||
return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset); | ||
const lineOffset = lineOffsets[position.line]; | ||
if (position.character <= 0) { | ||
return lineOffset; | ||
} | ||
const nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length; | ||
const offset = Math.min(lineOffset + position.character, nextLineOffset); | ||
return this.ensureBeforeEOL(offset, lineOffset); | ||
} | ||
ensureBeforeEOL(offset, lineOffset) { | ||
while (offset > lineOffset && isEOL(this._content.charCodeAt(offset - 1))) { | ||
offset--; | ||
} | ||
return offset; | ||
} | ||
get lineCount() { | ||
@@ -123,3 +134,3 @@ return this.getLineOffsets().length; | ||
static isIncremental(event) { | ||
let candidate = event; | ||
const candidate = event; | ||
return candidate !== undefined && candidate !== null && | ||
@@ -130,3 +141,3 @@ typeof candidate.text === 'string' && candidate.range !== undefined && | ||
static isFull(event) { | ||
let candidate = event; | ||
const candidate = event; | ||
return candidate !== undefined && candidate !== null && | ||
@@ -170,5 +181,5 @@ typeof candidate.text === 'string' && candidate.range === undefined && candidate.rangeLength === undefined; | ||
function applyEdits(document, edits) { | ||
let text = document.getText(); | ||
let sortedEdits = mergeSort(edits.map(getWellformedEdit), (a, b) => { | ||
let diff = a.range.start.line - b.range.start.line; | ||
const text = document.getText(); | ||
const sortedEdits = mergeSort(edits.map(getWellformedEdit), (a, b) => { | ||
const diff = a.range.start.line - b.range.start.line; | ||
if (diff === 0) { | ||
@@ -182,3 +193,3 @@ return a.range.start.character - b.range.start.character; | ||
for (const e of sortedEdits) { | ||
let startOffset = document.offsetAt(e.range.start); | ||
const startOffset = document.offsetAt(e.range.start); | ||
if (startOffset < lastModifiedOffset) { | ||
@@ -214,3 +225,3 @@ throw new Error('Overlapping edit'); | ||
while (leftIdx < left.length && rightIdx < right.length) { | ||
let ret = compare(left[leftIdx], right[rightIdx]); | ||
const ret = compare(left[leftIdx], right[rightIdx]); | ||
if (ret <= 0) { | ||
@@ -236,4 +247,4 @@ // smaller_equal -> take left to preserve order | ||
for (let i = 0; i < text.length; i++) { | ||
let ch = text.charCodeAt(i); | ||
if (ch === 13 /* CharCode.CarriageReturn */ || ch === 10 /* CharCode.LineFeed */) { | ||
const ch = text.charCodeAt(i); | ||
if (isEOL(ch)) { | ||
if (ch === 13 /* CharCode.CarriageReturn */ && i + 1 < text.length && text.charCodeAt(i + 1) === 10 /* CharCode.LineFeed */) { | ||
@@ -247,2 +258,5 @@ i++; | ||
} | ||
function isEOL(char) { | ||
return char === 13 /* CharCode.CarriageReturn */ || char === 10 /* CharCode.LineFeed */; | ||
} | ||
function getWellformedRange(range) { | ||
@@ -249,0 +263,0 @@ const start = range.start; |
@@ -133,2 +133,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
var line = low - 1; | ||
offset = this.ensureBeforeEOL(offset, lineOffsets[line]); | ||
return { line: line, character: offset - lineOffsets[line] }; | ||
@@ -145,5 +146,15 @@ }; | ||
var lineOffset = lineOffsets[position.line]; | ||
if (position.character <= 0) { | ||
return lineOffset; | ||
} | ||
var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length; | ||
return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset); | ||
var offset = Math.min(lineOffset + position.character, nextLineOffset); | ||
return this.ensureBeforeEOL(offset, lineOffset); | ||
}; | ||
FullTextDocument.prototype.ensureBeforeEOL = function (offset, lineOffset) { | ||
while (offset > lineOffset && isEOL(this._content.charCodeAt(offset - 1))) { | ||
offset--; | ||
} | ||
return offset; | ||
}; | ||
Object.defineProperty(FullTextDocument.prototype, "lineCount", { | ||
@@ -269,3 +280,3 @@ get: function () { | ||
var ch = text.charCodeAt(i); | ||
if (ch === 13 /* CharCode.CarriageReturn */ || ch === 10 /* CharCode.LineFeed */) { | ||
if (isEOL(ch)) { | ||
if (ch === 13 /* CharCode.CarriageReturn */ && i + 1 < text.length && text.charCodeAt(i + 1) === 10 /* CharCode.LineFeed */) { | ||
@@ -279,2 +290,5 @@ i++; | ||
} | ||
function isEOL(char) { | ||
return char === 13 /* CharCode.CarriageReturn */ || char === 10 /* CharCode.LineFeed */; | ||
} | ||
function getWellformedRange(range) { | ||
@@ -281,0 +295,0 @@ var start = range.start; |
{ | ||
"name": "vscode-languageserver-textdocument", | ||
"description": "A simple text document implementation for Node LSP servers", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"author": "Microsoft Corporation", | ||
@@ -20,2 +20,3 @@ "license": "MIT", | ||
"browser": "./lib/esm/main.js", | ||
"module": "./lib/esm/main.js", | ||
"import": "./lib/esm/main.js", | ||
@@ -28,10 +29,10 @@ "default": "./lib/umd/main.js" | ||
"prepack": "npm run all:publish", | ||
"compile": "node ../build/bin/tsc -b ./tsconfig.json", | ||
"clean": "node ../node_modules/.bin/rimraf lib", | ||
"watch": "node ../build/bin/tsc -b ./tsconfig.watch.json -w", | ||
"lint": "node ../node_modules/eslint/bin/eslint.js --ext ts src", | ||
"compile": "tsc -b ./tsconfig.json", | ||
"clean": "rimraf lib", | ||
"watch": "tsc -b ./tsconfig.watch.json -w", | ||
"lint": "eslint --ext ts src", | ||
"test": "node ../node_modules/mocha/bin/_mocha", | ||
"all": "npm run clean && npm run compile && npm run lint && npm run test", | ||
"compile:esm": "node ../build/bin/tsc -b ./tsconfig.esm.publish.json && node ../build/bin/fix-esm", | ||
"compile:umd": "node ../build/bin/tsc -b ./tsconfig.umd.publish.json", | ||
"compile:esm": "tsc -b ./tsconfig.esm.publish.json && node ../build/bin/fix-esm", | ||
"compile:umd": "tsc -b ./tsconfig.umd.publish.json", | ||
"all:publish": "git clean -xfd . && npm install && npm run compile:esm && npm run compile:umd && npm run lint && npm run test", | ||
@@ -38,0 +39,0 @@ "preversion": "npm test" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40277
949