mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-07-05 19:10:58 +00:00
Resolve JSON pointers as links
This commit is contained in:
parent
13a21cba5d
commit
0da9f2cdfd
5 changed files with 38 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ files:
|
||||||
- Formatting using Prettier
|
- Formatting using Prettier
|
||||||
- Document Symbols
|
- Document Symbols
|
||||||
- Automatically load remote schema files (by enabling DiagnosticsOptions.enableSchemaRequest)
|
- Automatically load remote schema files (by enabling DiagnosticsOptions.enableSchemaRequest)
|
||||||
|
- Links from JSON references.
|
||||||
|
|
||||||
Schemas can also be provided by configuration. See
|
Schemas can also be provided by configuration. See
|
||||||
[here](https://github.com/remcohaszing/monaco-yaml/blob/main/index.d.ts) for the API that the plugin
|
[here](https://github.com/remcohaszing/monaco-yaml/blob/main/index.d.ts) for the API that the plugin
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,11 @@ array:
|
||||||
enum: Mewtwo
|
enum: Mewtwo
|
||||||
|
|
||||||
|
|
||||||
|
# JSON referenses can be clicked for navigation
|
||||||
|
pointer:
|
||||||
|
$ref: '#/array'
|
||||||
|
|
||||||
|
|
||||||
formatting: Formatting is supported too! Under the hood this is powered by Prettier. Just press Ctrl+Shift+I or right click and press Format to format this document.
|
formatting: Formatting is supported too! Under the hood this is powered by Prettier. Just press Ctrl+Shift+I or right click and press Format to format this document.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -425,3 +425,26 @@ export function createDocumentFormattingEditProvider(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toLink(link: ls.DocumentLink): languages.ILink {
|
||||||
|
return {
|
||||||
|
range: toRange(link.range),
|
||||||
|
tooltip: link.tooltip,
|
||||||
|
url: link.target,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createLinkProvider(getWorker: WorkerAccessor): languages.LinkProvider {
|
||||||
|
return {
|
||||||
|
async provideLinks(model) {
|
||||||
|
const resource = model.uri;
|
||||||
|
|
||||||
|
const worker = await getWorker(resource);
|
||||||
|
const links = await worker.findLinks(String(resource));
|
||||||
|
|
||||||
|
return {
|
||||||
|
links: links.map(toLink),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
createDocumentFormattingEditProvider,
|
createDocumentFormattingEditProvider,
|
||||||
createDocumentSymbolProvider,
|
createDocumentSymbolProvider,
|
||||||
createHoverProvider,
|
createHoverProvider,
|
||||||
|
createLinkProvider,
|
||||||
WorkerAccessor,
|
WorkerAccessor,
|
||||||
} from './languageFeatures';
|
} from './languageFeatures';
|
||||||
import { createWorkerManager } from './workerManager';
|
import { createWorkerManager } from './workerManager';
|
||||||
|
|
@ -62,6 +63,7 @@ export function setupMode(defaults: languages.yaml.LanguageServiceDefaults): voi
|
||||||
languageId,
|
languageId,
|
||||||
createDocumentFormattingEditProvider(worker),
|
createDocumentFormattingEditProvider(worker),
|
||||||
),
|
),
|
||||||
|
languages.registerLinkProvider(languageId, createLinkProvider(worker)),
|
||||||
createDiagnosticsAdapter(languageId, worker, defaults),
|
createDiagnosticsAdapter(languageId, worker, defaults),
|
||||||
languages.setLanguageConfiguration(languageId, richEditConfiguration),
|
languages.setLanguageConfiguration(languageId, richEditConfiguration),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ export interface YAMLWorker {
|
||||||
resetSchema: (uri: string) => PromiseLike<boolean>;
|
resetSchema: (uri: string) => PromiseLike<boolean>;
|
||||||
|
|
||||||
findDocumentSymbols: (uri: string) => PromiseLike<ls.DocumentSymbol[]>;
|
findDocumentSymbols: (uri: string) => PromiseLike<ls.DocumentSymbol[]>;
|
||||||
|
|
||||||
|
findLinks: (uri: string) => PromiseLike<ls.DocumentLink[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createYAMLWorker(
|
export function createYAMLWorker(
|
||||||
|
|
@ -89,6 +91,11 @@ export function createYAMLWorker(
|
||||||
const symbols = languageService.findDocumentSymbols2(document, {});
|
const symbols = languageService.findDocumentSymbols2(document, {});
|
||||||
return Promise.resolve(symbols);
|
return Promise.resolve(symbols);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
findLinks(uri) {
|
||||||
|
const document = getTextDocument(uri);
|
||||||
|
return Promise.resolve(languageService.findLinks(document));
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue