@@ -2,13 +2,12 @@ import { Project } from "@marko/language-tools";
2
2
import fs from "fs" ;
3
3
import snapshot from "mocha-snap" ;
4
4
import path from "path" ;
5
- import { CancellationToken , Position } from "vscode-languageserver" ;
6
- import { TextDocument } from "vscode-languageserver-textdocument" ;
5
+ import { Position } from "vscode-languageserver" ;
7
6
// import { bench, run } from "mitata";
8
- import { URI } from "vscode-uri " ;
7
+ import { TextDocument } from "vscode-languageserver-textdocument " ;
9
8
10
- import MarkoLangaugeService , { documents } from "../service" ;
11
9
import { codeFrame } from "./util/code-frame" ;
10
+ import { getLanguageServer } from "./util/language-service" ;
12
11
13
12
Project . setDefaultTypePaths ( {
14
13
internalTypesFile : require . resolve (
@@ -21,38 +20,33 @@ Project.setDefaultTypePaths({
21
20
// const BENCHED = new Set<string>();
22
21
const FIXTURE_DIR = path . join ( __dirname , "fixtures" ) ;
23
22
23
+ after ( async ( ) => {
24
+ const handle = await getLanguageServer ( ) ;
25
+ await handle . shutdown ( ) ;
26
+ } ) ;
27
+
24
28
for ( const subdir of fs . readdirSync ( FIXTURE_DIR ) ) {
25
29
const fixtureSubdir = path . join ( FIXTURE_DIR , subdir ) ;
26
30
27
31
if ( ! fs . statSync ( fixtureSubdir ) . isDirectory ( ) ) continue ;
28
32
for ( const entry of fs . readdirSync ( fixtureSubdir ) ) {
29
33
it ( entry , async ( ) => {
34
+ const serverHandle = await getLanguageServer ( ) ;
35
+
30
36
const fixtureDir = path . join ( fixtureSubdir , entry ) ;
31
37
32
38
for ( const filename of loadMarkoFiles ( fixtureDir ) ) {
33
- const doc = documents . get ( URI . file ( filename ) . toString ( ) ) ! ;
39
+ const doc = await serverHandle . openTextDocument ( filename , "marko" ) ;
34
40
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 ) ;
44
41
45
42
let results = "" ;
46
43
47
44
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 ,
55
48
) ;
49
+
56
50
const loc = { start : position , end : position } ;
57
51
58
52
let message = "" ;
@@ -87,9 +81,9 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
87
81
language : string ;
88
82
content : string ;
89
83
}
90
- | undefined = await MarkoLangaugeService . commands [
91
- "$/ showScriptOutput"
92
- ] ( doc . uri ) ;
84
+ | undefined = await serverHandle . sendExecuteCommandRequest (
85
+ "marko.debug. showScriptOutput" ,
86
+ ) ;
93
87
if ( scriptOutput ) {
94
88
await snapshot ( scriptOutput . content , {
95
89
file : path . relative (
@@ -108,8 +102,8 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
108
102
language : string ;
109
103
content : string ;
110
104
}
111
- | undefined = await MarkoLangaugeService . commands [ "$/showHtmlOutput" ] (
112
- doc . uri ,
105
+ | undefined = await serverHandle . sendExecuteCommandRequest (
106
+ "marko.debug.showHtmlOutput" ,
113
107
) ;
114
108
if ( htmlOutput ) {
115
109
await snapshot ( htmlOutput . content , {
@@ -121,12 +115,15 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
121
115
} ) ;
122
116
}
123
117
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
+ ) {
127
125
results += "## Diagnostics\n" ;
128
-
129
- for ( const error of errors ) {
126
+ for ( const error of diagnosticReport . items ) {
130
127
const loc = {
131
128
start : error . range . start ,
132
129
end : error . range . end ,
@@ -137,7 +134,7 @@ for (const subdir of fs.readdirSync(FIXTURE_DIR)) {
137
134
}
138
135
}
139
136
140
- documents . doClose ( params ) ;
137
+ await serverHandle . closeTextDocument ( doc . uri ) ;
141
138
142
139
await snapshot ( results , {
143
140
file : path . relative ( fixtureDir , filename . replace ( / \. m a r k o $ / , ".md" ) ) ,
0 commit comments