[mod] text
This commit is contained in:
parent
11d165f794
commit
d26fae56e4
2 changed files with 22 additions and 2 deletions
|
@ -5,7 +5,7 @@ tests for position test
|
||||||
@date: 2025/08/11
|
@date: 2025/08/11
|
||||||
:)
|
:)
|
||||||
module namespace test = 'lsp/test/position';
|
module namespace test = 'lsp/test/position';
|
||||||
|
import module namespace lspt = 'lsp-typedefs' at "../webapp/lsp/lsp-typedefs.xqm";
|
||||||
import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
|
import module namespace pos="lsp/position" at "../webapp/lsp/position.xqm";
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ declare %unit:test function test:line-count() {
|
||||||
(:~ convert position. :)
|
(:~ convert position. :)
|
||||||
declare %unit:test function test:resolvePosition() {
|
declare %unit:test function test:resolvePosition() {
|
||||||
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
|
let $text:=unparsed-text("sample.docs/pdfbox.xqm")
|
||||||
let $p:= pos:resolvePosition($text,pos:Position(518,33))
|
let $p:= pos:resolvePosition($text,lspt:Position(518,33))
|
||||||
return unit:assert-equals($p,18751)
|
return unit:assert-equals($p,18751)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,26 @@ declare record text:rec(
|
||||||
line? := %method fn($line) {?lines[$line]}
|
line? := %method fn($line) {?lines[$line]}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
(:~ json numbers :)
|
||||||
|
declare type text:num as (xs:integer|xs:double);
|
||||||
|
|
||||||
|
(:~
|
||||||
|
@param line Line position in a document (zero-based).
|
||||||
|
@param character Character offset on a line in a document (zero-based).
|
||||||
|
:)
|
||||||
|
declare record text:Position(
|
||||||
|
line as text:num,
|
||||||
|
character as text:num
|
||||||
|
);
|
||||||
|
|
||||||
|
(:~
|
||||||
|
@param line Line position in a document (zero-based).
|
||||||
|
@param character Character offset on a line in a document (zero-based).
|
||||||
|
:)
|
||||||
|
declare record text:Range(
|
||||||
|
start as text:Position,
|
||||||
|
end as text:Position
|
||||||
|
);
|
||||||
declare function text:build($text as xs:string){
|
declare function text:build($text as xs:string){
|
||||||
let $lines:=tokenize($text, '(\r\n?|\n\r?)')
|
let $lines:=tokenize($text, '(\r\n?|\n\r?)')
|
||||||
return text:rec($lines)
|
return text:rec($lines)
|
||||||
|
|
Loading…
Add table
Reference in a new issue