vscode-languageserver-textdocument#Position TypeScript Examples
The following examples show how to use
vscode-languageserver-textdocument#Position.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: navigation.test.ts From macro-executor with MIT License | 6 votes |
function assertLocation(service: LanguageService, input: string, position:Position, location:Location, f:locationFunction) {
let uri = 'test://test/test.src';
let document = TextDocument.create(uri, 'macro', 0, input);
documents.set(uri, document);
let macroFile = service.parseMacroFile(document);
let result = f(document, position, macroFile);
assert.strictEqual(result.uri, location.uri, input);
assert.strictEqual(result.range.start.line, location.range.start.line, input);
assert.strictEqual(result.range.start.character, location.range.start.character, input);
assert.strictEqual(result.range.end.line, location.range.end.line, input);
assert.strictEqual(result.range.end.character, location.range.end.character, input);
}
Example #2
Source File: navigation.test.ts From macro-executor with MIT License | 6 votes |
function assertLocations(service: LanguageService, input: string, position:Position, locations:Location[], f:locationsFunction) {
let uri = 'test://test/test.src';
let document = TextDocument.create(uri, 'macro', 0, input);
documents.set(uri, document);
let macroFile = service.parseMacroFile(document);
let result = f(document, position, macroFile);
assert.strictEqual(result.length, locations.length);
for (let i = 0; i < result.length; i++) {
assert.strictEqual(result[i].uri, locations[i].uri, input);
assert.strictEqual(result[i].range.start.line, locations[i].range.start.line, input);
assert.strictEqual(result[i].range.start.character, locations[i].range.start.character, input);
assert.strictEqual(result[i].range.end.line, locations[i].range.end.line, input);
assert.strictEqual(result[i].range.end.character, locations[i].range.end.character, input);
}
}
Example #3
Source File: server.ts From vscode-css-variables with MIT License | 6 votes |
export function indexToPosition(str: string, index: number): Position {
const data = lineColumn(str + '\n', index);
if (!data) {
console.log(str, index);
return { line: 0, character: 0 };
}
const { line, col } = data;
return { line: line - 1, character: col - 1 };
}
Example #4
Source File: server.ts From vscode-css-variables with MIT License | 5 votes |
connection.onDocumentColor((params): ColorInformation[] => {
const document = documents.get(params.textDocument.uri);
if (!document) {
return [];
}
const colors: ColorInformation[] = [];
const text = document.getText();
const matches = findAll(/var\((?<varName>--[a-z-0-9]+)/g, text);
const globalStart: Position = { line: 0, character: 0 };
matches.map((match) => {
const start = indexToPosition(text, match.index + 4);
const end = indexToPosition(
text,
match.index + match[0].length
);
const cssVariable = cachedVariables['all']?.get(match.groups.varName);
if (cssVariable?.color) {
const range = {
start: {
line: globalStart.line + start.line,
character:
(end.line === 0 ? globalStart.character : 0) + start.character,
},
end: {
line: globalStart.line + end.line,
character:
(end.line === 0 ? globalStart.character : 0) + end.character,
},
};
colors.push({
color: cssVariable.color,
range,
});
}
});
return colors;
});