1
1
import type { Service } from '@volar/language-service'
2
- import * as json from 'vscode-json-languageservice'
3
- import pagesJsonSchema from '@uni-helper/pages-json-schema/schema.json'
2
+ import { type LanguageService } from 'yaml-language-server'
3
+ import type * as json from 'vscode-json-languageservice'
4
+ import { type TextDocument } from 'vscode-languageserver-textdocument'
5
+ import { createJsonLs } from './jsonLs'
6
+ import { createYamlLs } from './yamlLs'
7
+ import { isYaml } from './utils'
4
8
5
- type TextDocument = any
6
-
7
- pagesJsonSchema . $ref = '#/definitions/PageMetaDatum'
8
- pagesJsonSchema . definitions . PageMetaDatum . required = [ ]
9
9
export interface Provide {
10
10
'json/jsonDocument' : ( document : TextDocument ) => json . JSONDocument | undefined
11
11
'json/languageService' : ( ) => json . LanguageService
12
+ 'yaml/languageService' : ( ) => LanguageService
12
13
}
13
14
14
15
export default ( ) : Service < Provide > => ( context ) : ReturnType < Service < Provide > > => {
@@ -19,30 +20,39 @@ export default (): Service<Provide> => (context): ReturnType<Service<Provide>> =
19
20
return { triggerCharacters } as any
20
21
21
22
const jsonDocuments = new WeakMap < TextDocument , [ number , json . JSONDocument ] > ( )
22
- const jsonLs = json . getLanguageService ( { } )
23
- jsonLs . configure ( {
24
- allowComments : true ,
25
- schemas : [
26
- {
27
- fileMatch : [ '*.customBlock_route_*.json*' ] ,
28
- uri : 'foo://route-custom-block.schema.json' ,
29
- schema : {
30
- ...pagesJsonSchema ,
31
- } ,
32
- } ,
33
- ] ,
34
- } )
23
+ const jsonLs = createJsonLs ( context )
24
+ const yamlLs = createYamlLs ( context )
35
25
36
26
return {
37
27
38
28
provide : {
39
29
'json/jsonDocument' : getJsonDocument ,
40
30
'json/languageService' : ( ) => jsonLs ,
31
+ 'yaml/languageService' : ( ) => yamlLs ,
41
32
} ,
42
33
43
34
triggerCharacters,
44
35
36
+ provideCodeActions ( document , range , context ) {
37
+ if ( isYaml ( document ) ) {
38
+ return yamlLs . getCodeAction ( document , {
39
+ context,
40
+ range,
41
+ textDocument : document ,
42
+ } )
43
+ }
44
+ } ,
45
+
46
+ provideCodeLenses ( document ) {
47
+ if ( isYaml ( document ) )
48
+ return yamlLs . getCodeLens ( document )
49
+
50
+ } ,
51
+
45
52
provideCompletionItems ( document , position ) {
53
+ if ( isYaml ( document ) )
54
+ return yamlLs . doComplete ( document , position , false )
55
+
46
56
return worker ( document , async ( jsonDocument ) => {
47
57
return await jsonLs . doComplete ( document , position , jsonDocument )
48
58
} )
@@ -53,12 +63,18 @@ export default (): Service<Provide> => (context): ReturnType<Service<Provide>> =
53
63
} ,
54
64
55
65
provideDefinition ( document , position ) {
66
+ if ( isYaml ( document ) )
67
+ return yamlLs . doDefinition ( document , { position, textDocument : document } )
68
+
56
69
return worker ( document , async ( jsonDocument ) => {
57
70
return await jsonLs . findDefinition ( document , position , jsonDocument )
58
71
} )
59
72
} ,
60
73
61
74
provideDiagnostics ( document ) {
75
+ if ( isYaml ( document ) )
76
+ return yamlLs . doValidation ( document , false )
77
+
62
78
return worker ( document , async ( jsonDocument ) => {
63
79
const documentLanguageSettings = undefined // await getSettings(); // TODO
64
80
@@ -71,19 +87,29 @@ export default (): Service<Provide> => (context): ReturnType<Service<Provide>> =
71
87
} )
72
88
} ,
73
89
90
+
74
91
provideHover ( document , position ) {
92
+ if ( isYaml ( document ) )
93
+ return yamlLs . doHover ( document , position )
94
+
75
95
return worker ( document , async ( jsonDocument ) => {
76
96
return await jsonLs . doHover ( document , position , jsonDocument )
77
97
} )
78
98
} ,
79
99
80
100
provideDocumentLinks ( document ) {
101
+ if ( isYaml ( document ) )
102
+ return yamlLs . findLinks ( document )
103
+
81
104
return worker ( document , async ( jsonDocument ) => {
82
105
return await jsonLs . findLinks ( document , jsonDocument )
83
106
} )
84
107
} ,
85
108
86
109
provideDocumentSymbols ( document ) {
110
+ if ( isYaml ( document ) )
111
+ return yamlLs . findDocumentSymbols2 ( document , { } )
112
+
87
113
return worker ( document , async ( jsonDocument ) => {
88
114
return await jsonLs . findDocumentSymbols2 ( document , jsonDocument )
89
115
} )
@@ -102,17 +128,28 @@ export default (): Service<Provide> => (context): ReturnType<Service<Provide>> =
102
128
} ,
103
129
104
130
provideFoldingRanges ( document ) {
131
+ if ( isYaml ( document ) )
132
+ return yamlLs . getFoldingRanges ( document , { } )
133
+
134
+
105
135
return worker ( document , async ( ) => {
106
136
return await jsonLs . getFoldingRanges ( document )
107
137
} )
108
138
} ,
109
139
110
140
provideSelectionRanges ( document , positions ) {
141
+ if ( isYaml ( document ) )
142
+ return yamlLs . getSelectionRanges ( document , positions )
143
+
111
144
return worker ( document , async ( jsonDocument ) => {
112
145
return await jsonLs . getSelectionRanges ( document , positions , jsonDocument )
113
146
} )
114
147
} ,
115
148
149
+ resolveCodeLens ( codeLens ) {
150
+ return yamlLs . resolveCodeLens ( codeLens )
151
+ } ,
152
+
116
153
provideDocumentFormattingEdits ( document , range , options ) {
117
154
return worker ( document , async ( ) => {
118
155
const options_2 = await context . env . getConfiguration ?.< json . FormattingOptions & { enable : boolean } > ( 'json.format' )
0 commit comments