@@ -2,13 +2,12 @@ import { Project } from "@marko/language-tools";
22import fs from "fs" ;
33import snapshot from "mocha-snap" ;
44import path from "path" ;
5- import { CancellationToken , Position } from "vscode-languageserver" ;
6- import { TextDocument } from "vscode-languageserver-textdocument" ;
5+ import { Position } from "vscode-languageserver" ;
76// import { bench, run } from "mitata";
8- import { URI } from "vscode-uri " ;
7+ import { TextDocument } from "vscode-languageserver-textdocument " ;
98
10- import MarkoLangaugeService , { documents } from "../service" ;
119import { codeFrame } from "./util/code-frame" ;
10+ import { getLanguageServer } from "./util/language-service" ;
1211
1312Project . setDefaultTypePaths ( {
1413 internalTypesFile : require . resolve (
@@ -21,38 +20,33 @@ Project.setDefaultTypePaths({
2120// const BENCHED = new Set<string>();
2221const FIXTURE_DIR = path . join ( __dirname , "fixtures" ) ;
2322
23+ after ( async ( ) => {
24+ const handle = await getLanguageServer ( ) ;
25+ await handle . shutdown ( ) ;
26+ } ) ;
27+
2428for ( const subdir of fs . readdirSync ( FIXTURE_DIR ) ) {
2529 const fixtureSubdir = path . join ( FIXTURE_DIR , subdir ) ;
2630
2731 if ( ! fs . statSync ( fixtureSubdir ) . isDirectory ( ) ) continue ;
2832 for ( const entry of fs . readdirSync ( fixtureSubdir ) ) {
2933 it ( entry , async ( ) => {
34+ const serverHandle = await getLanguageServer ( ) ;
35+
3036 const fixtureDir = path . join ( fixtureSubdir , entry ) ;
3137
3238 for ( const filename of loadMarkoFiles ( fixtureDir ) ) {
33- const doc = documents . get ( URI . file ( filename ) . toString ( ) ) ! ;
39+ const doc = await serverHandle . openTextDocument ( filename , "marko" ) ;
3440 const code = doc . getText ( ) ;
35- const params = {
36- textDocument : {
37- uri : doc . uri ,
38- languageId : doc . languageId ,
39- version : doc . version ,
40- text : code ,
41- } ,
42- } as const ;
43- documents . doOpen ( params ) ;
4441
4542 let results = "" ;
4643
4744 for ( const position of getHovers ( doc ) ) {
48- const hoverInfo = await MarkoLangaugeService . doHover (
49- doc ,
50- {
51- position,
52- textDocument : doc ,
53- } ,
54- CancellationToken . None ,
45+ const hoverInfo = await serverHandle . sendHoverRequest (
46+ doc . uri ,
47+ position ,
5548 ) ;
49+
5650 const loc = { start : position , end : position } ;
5751
5852 let message = "" ;
@@ -87,9 +81,9 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
8781 language : string ;
8882 content : string ;
8983 }
90- | undefined = await MarkoLangaugeService . commands [
91- "$/ showScriptOutput"
92- ] ( doc . uri ) ;
84+ | undefined = await serverHandle . sendExecuteCommandRequest (
85+ "marko.debug. showScriptOutput" ,
86+ ) ;
9387 if ( scriptOutput ) {
9488 await snapshot ( scriptOutput . content , {
9589 file : path . relative (
@@ -108,8 +102,8 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
108102 language : string ;
109103 content : string ;
110104 }
111- | undefined = await MarkoLangaugeService . commands [ "$/showHtmlOutput" ] (
112- doc . uri ,
105+ | undefined = await serverHandle . sendExecuteCommandRequest (
106+ "marko.debug.showHtmlOutput" ,
113107 ) ;
114108 if ( htmlOutput ) {
115109 await snapshot ( htmlOutput . content , {
@@ -121,12 +115,15 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
121115 } ) ;
122116 }
123117
124- const errors = await MarkoLangaugeService . doValidate ( doc ) ;
125-
126- if ( errors && errors . length ) {
118+ const diagnosticReport =
119+ await serverHandle . sendDocumentDiagnosticRequest ( doc . uri ) ;
120+ if (
121+ diagnosticReport . kind === "full" &&
122+ diagnosticReport . items &&
123+ diagnosticReport . items . length
124+ ) {
127125 results += "## Diagnostics\n" ;
128-
129- for ( const error of errors ) {
126+ for ( const error of diagnosticReport . items ) {
130127 const loc = {
131128 start : error . range . start ,
132129 end : error . range . end ,
@@ -137,7 +134,7 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
137134 }
138135 }
139136
140- documents . doClose ( params ) ;
137+ await serverHandle . closeTextDocument ( doc . uri ) ;
141138
142139 await snapshot ( results , {
143140 file : path . relative ( fixtureDir , filename . replace ( / \. m a r k o $ / , ".md" ) ) ,
0 commit comments