Skip to content

Commit

Permalink
fix: json schemaRequestService missing
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 14, 2022
1 parent 5749679 commit 3852ee8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 28 deletions.
5 changes: 4 additions & 1 deletion packages/vue-language-service/src/documentService.ts
Expand Up @@ -25,6 +25,7 @@ import useVuePlugin from './vuePlugins/vue';
import type * as _ from 'vscode-languageserver-protocol';
import { loadCustomPlugins } from './languageService';
import { EmbeddedLanguagePlugin } from '@volar/vue-language-service-types';
import * as json from 'vscode-json-languageservice';

export interface DocumentService extends ReturnType<typeof getDocumentService> { }

Expand All @@ -41,6 +42,8 @@ export function getDocumentService(
const services = createBasicRuntime();
let tsLs: ts2.LanguageService;

const jsonLs = json.getLanguageService({ /* schemaRequestService: vueHost?.schemaRequestService */ });

// language support plugins
const _getSettings: <T>(section: string, scopeUri?: string | undefined) => Promise<T | undefined> = async (section, scopeUri) => getSettings?.(section, scopeUri);
const customPlugins = loadCustomPlugins(rootPath);
Expand All @@ -63,7 +66,7 @@ export function getDocumentService(
getStylesheet: services.getStylesheet
});
const jsonPlugin = useJsonPlugin({
getJsonLs: () => services.jsonLs,
getJsonLs: () => jsonLs,
});
const tsPlugin = useTsPlugin({
getTsLs: () => tsLs,
Expand Down
5 changes: 4 additions & 1 deletion packages/vue-language-service/src/languageService.ts
Expand Up @@ -44,6 +44,7 @@ import useScriptSetupConversionsPlugin from './vuePlugins/scriptSetupConversions
import useTagNameCasingConversionsPlugin from './vuePlugins/tagNameCasingConversions';
import useVuePlugin, { triggerCharacters as vueTriggerCharacters } from './vuePlugins/vue';
import useVueTemplateLanguagePlugin, { semanticTokenTypes as vueTemplateSemanticTokenTypes, triggerCharacters as vueTemplateLanguageTriggerCharacters } from './vuePlugins/vueTemplateLanguage';
import * as json from 'vscode-json-languageservice';

import type * as _0 from 'vscode-html-languageservice';
import type * as _1 from 'vscode-css-languageservice';
Expand Down Expand Up @@ -115,6 +116,8 @@ export function createLanguageService(
const blockingRequests = new Set<Promise<any>>();
const tsTriggerCharacters = getTsTriggerCharacters(ts.version);

const jsonLs = json.getLanguageService({ schemaRequestService: vueHost?.schemaRequestService });

// plugins
const _getSettings: <T>(section: string, scopeUri?: string | undefined) => Promise<T | undefined> = async (section, scopeUri) => getSettings?.(section, scopeUri);
const customPlugins = loadCustomPlugins(vueHost.getCurrentDirectory()).map(plugin => defineLanguageServicePlugin(plugin));
Expand Down Expand Up @@ -160,7 +163,7 @@ export function createLanguageService(
);
const jsonPlugin = defineLanguageServicePlugin(
useJsonPlugin({
getJsonLs: () => services.jsonLs,
getJsonLs: () => jsonLs,
schema: undefined, // TODO
}),
{
Expand Down
1 change: 0 additions & 1 deletion packages/vue-typescript/package.json
Expand Up @@ -26,7 +26,6 @@
"upath": "^2.0.1",
"vscode-css-languageservice": "^5.1.9",
"vscode-html-languageservice": "^4.2.1",
"vscode-json-languageservice": "^4.1.10",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3"
}
Expand Down
23 changes: 0 additions & 23 deletions packages/vue-typescript/src/basicRuntime.ts
Expand Up @@ -4,7 +4,6 @@ import { TextRange } from '@volar/vue-code-gen/out/types';
import * as fs from 'fs';
import * as css from 'vscode-css-languageservice';
import * as html from 'vscode-html-languageservice';
import * as json from 'vscode-json-languageservice';
import { TextDocument } from 'vscode-languageserver-textdocument';
import * as pug from '@volar/pug-language-service';
import { findClassNames } from './parsers/cssClasses';
Expand Down Expand Up @@ -58,7 +57,6 @@ export function createBasicRuntime() {
const scssLs = css.getSCSSLanguageService({ fileSystemProvider });
const lessLs = css.getLESSLanguageService({ fileSystemProvider });
const pugLs = pug.getLanguageService(htmlLs);
const jsonLs = json.getLanguageService({ /* schemaRequestService: vueHost?.schemaRequestService */ });
const postcssLs: css.LanguageService = {
...scssLs,
doValidation: (document, stylesheet, documentSettings) => {
Expand All @@ -75,20 +73,17 @@ export function createBasicRuntime() {
const stylesheetVBinds = new WeakMap<css.Stylesheet, TextRange[]>();
const stylesheetClasses = new WeakMap<css.Stylesheet, Record<string, [number, number][]>>();
const htmlDocuments = new WeakMap<TextDocument, [number, html.HTMLDocument]>();
const jsonDocuments = new WeakMap<TextDocument, [number, json.JSONDocument]>();
const pugDocuments = new WeakMap<TextDocument, [number, pug.PugDocument]>();

return {
fileSystemProvider,
htmlLs,
pugLs,
jsonLs,
getCssLs,
getStylesheet,
getCssVBindRanges,
getCssClasses,
getHtmlDocument,
getJsonDocument,
getPugDocument,
updateHtmlCustomData,
updateCssCustomData,
Expand Down Expand Up @@ -252,24 +247,6 @@ export function createBasicRuntime() {

return doc;
}
function getJsonDocument(document: TextDocument) {

if (document.languageId !== 'json' && document.languageId !== 'jsonc')
return;

const cache = jsonDocuments.get(document);
if (cache) {
const [cacheVersion, cacheDoc] = cache;
if (cacheVersion === document.version) {
return cacheDoc;
}
}

const doc = jsonLs.parseJSONDocument(document);
jsonDocuments.set(document, [document.version, doc]);

return doc;
}
function getPugDocument(document: TextDocument) {

if (document.languageId !== 'jade')
Expand Down
2 changes: 0 additions & 2 deletions packages/vue-typescript/src/types.ts
Expand Up @@ -42,11 +42,9 @@ export type BasicRuntimeContext = {

htmlLs: html.LanguageService,
pugLs: pug.LanguageService,
jsonLs: json.LanguageService,
getCssLs: (lang: string) => css.LanguageService | undefined,
getStylesheet: (documrnt: TextDocument) => css.Stylesheet | undefined,
getHtmlDocument: (documrnt: TextDocument) => html.HTMLDocument | undefined,
getJsonDocument: (documrnt: TextDocument) => json.JSONDocument | undefined,
getPugDocument: (documrnt: TextDocument) => pug.PugDocument | undefined,
}

Expand Down

0 comments on commit 3852ee8

Please sign in to comment.