Skip to content

Commit

Permalink
fix(css, html, json, yaml): failed to resolve relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 14, 2024
1 parent b4877d2 commit ea87a14
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export function create({
getDocumentContext = context => {
return {
resolveReference(ref, base) {
const decoded = context.decodeEmbeddedDocumentUri(base);
if (decoded) {
base = decoded[0];
}
if (ref.match(/^\w[\w\d+.-]*:/)) {
// starts with a schema
return ref;
Expand Down
6 changes: 5 additions & 1 deletion packages/html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export function create({
getDocumentContext = context => {
return {
resolveReference(ref, base) {
const decoded = context.decodeEmbeddedDocumentUri(base);
if (decoded) {
base = decoded[0];
}
if (ref.match(/^\w[\w\d+.-]*:/)) {
// starts with a schema
return ref;
Expand Down Expand Up @@ -111,7 +115,7 @@ export function create({
const fileSystemProvider: html.FileSystemProvider = {
stat: async uri => await context.env.fs?.stat(uri)
?? { type: html.FileType.Unknown, ctime: 0, mtime: 0, size: 0 },
readDirectory: async uri => context.env.fs?.readDirectory(uri) ?? [],
readDirectory: async uri => await context.env.fs?.readDirectory(uri) ?? [],
};
const documentContext = getDocumentContext(context);
const htmlLs = html.getLanguageService({
Expand Down
6 changes: 5 additions & 1 deletion packages/json/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export interface JSONSchemaSettings {

export function create({
documentSelector = ['json', 'jsonc'],
getWorkspaceContextService = () => {
getWorkspaceContextService = context => {
return {
resolveRelativePath(relativePath, resource) {
const decoded = context.decodeEmbeddedDocumentUri(resource);
if (decoded) {
resource = decoded[0];
}
const base = resource.substring(0, resource.lastIndexOf('/') + 1);
return Utils.resolvePath(URI.parse(base), relativePath).toString();
},
Expand Down
6 changes: 5 additions & 1 deletion packages/yaml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ function noop(): undefined { }
*/
export function create({
documentSelector = ['yaml'],
getWorkspaceContextService = () => {
getWorkspaceContextService = context => {
return {
resolveRelativePath(relativePath, resource) {
const decoded = context.decodeEmbeddedDocumentUri(resource);
if (decoded) {
resource = decoded[0];
}
const base = resource.substring(0, resource.lastIndexOf('/') + 1);
return Utils.resolvePath(URI.parse(base), relativePath).toString();
},
Expand Down

0 comments on commit ea87a14

Please sign in to comment.