monaco-yaml
Advanced tools
Comparing version 4.0.0-alpha.2 to 4.0.0-alpha.3
import { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema'; | ||
import { IEvent } from 'monaco-editor'; | ||
@@ -93,2 +94,14 @@ export interface SchemasSettings { | ||
export interface LanguageServiceDefaults { | ||
readonly onDidChange: IEvent<LanguageServiceDefaults>; | ||
readonly diagnosticsOptions: DiagnosticsOptions; | ||
setDiagnosticsOptions: (options: DiagnosticsOptions) => void; | ||
} | ||
export function createLanguageServiceDefaults( | ||
initialDiagnosticsOptions: DiagnosticsOptions, | ||
): LanguageServiceDefaults; | ||
export const yamlDefaults: LanguageServiceDefaults; | ||
/** | ||
@@ -95,0 +108,0 @@ * Configure `monaco-yaml` diagnostics options. |
91
index.js
@@ -9,2 +9,3 @@ // src/index.ts | ||
import { editor as editor2, languages as languages2 } from "monaco-editor/esm/vs/editor/editor.api.js"; | ||
import { registerMarkerDataProvider } from "monaco-marker-data-provider"; | ||
import { createWorkerManager } from "monaco-worker-manager"; | ||
@@ -14,3 +15,2 @@ | ||
import { | ||
editor, | ||
languages, | ||
@@ -60,58 +60,15 @@ MarkerSeverity, | ||
} | ||
function createDiagnosticsAdapter(getWorker, defaults) { | ||
const listeners = /* @__PURE__ */ new Map(); | ||
const resetSchema = async (resource) => { | ||
const worker = await getWorker(); | ||
worker.resetSchema(String(resource)); | ||
}; | ||
const doValidate = async (resource) => { | ||
const worker = await getWorker(resource); | ||
const diagnostics = await worker.doValidation(String(resource)); | ||
const markers = diagnostics.map(toDiagnostics); | ||
const model = editor.getModel(resource); | ||
if (model && model.getLanguageId() === languageId) { | ||
editor.setModelMarkers(model, languageId, markers); | ||
function createMarkerDataProvider(getWorker) { | ||
return { | ||
owner: languageId, | ||
async provideMarkerData(model) { | ||
const worker = await getWorker(model.uri); | ||
const diagnostics = await worker.doValidation(String(model.uri)); | ||
return diagnostics.map(toDiagnostics); | ||
}, | ||
async doReset(model) { | ||
const worker = await getWorker(model.uri); | ||
await worker.resetSchema(String(model.uri)); | ||
} | ||
}; | ||
const onModelAdd = (model) => { | ||
if (model.getLanguageId() !== languageId) { | ||
return; | ||
} | ||
let handle; | ||
listeners.set(String(model.uri), model.onDidChangeContent(() => { | ||
clearTimeout(handle); | ||
handle = setTimeout(() => doValidate(model.uri), 500); | ||
})); | ||
doValidate(model.uri); | ||
}; | ||
const onModelRemoved = (model) => { | ||
editor.setModelMarkers(model, languageId, []); | ||
const uriStr = String(model.uri); | ||
const listener = listeners.get(uriStr); | ||
if (listener) { | ||
listener.dispose(); | ||
listeners.delete(uriStr); | ||
} | ||
}; | ||
editor.onDidCreateModel(onModelAdd); | ||
editor.onWillDisposeModel((model) => { | ||
onModelRemoved(model); | ||
resetSchema(model.uri); | ||
}); | ||
editor.onDidChangeModelLanguage((event) => { | ||
onModelRemoved(event.model); | ||
onModelAdd(event.model); | ||
resetSchema(event.model.uri); | ||
}); | ||
defaults.onDidChange(() => { | ||
for (const model of editor.getModels()) { | ||
if (model.getLanguageId() === languageId) { | ||
onModelRemoved(model); | ||
onModelAdd(model); | ||
} | ||
} | ||
}); | ||
for (const model of editor.getModels()) { | ||
onModelAdd(model); | ||
} | ||
} | ||
@@ -238,2 +195,10 @@ function fromPosition(position) { | ||
} | ||
function toLocationLink(locationLink) { | ||
return { | ||
originSelectionRange: toRange(locationLink.originSelectionRange), | ||
range: toRange(locationLink.targetRange), | ||
targetSelectionRange: toRange(locationLink.targetSelectionRange), | ||
uri: Uri.parse(locationLink.targetUri) | ||
}; | ||
} | ||
function createDefinitionProvider(getWorker) { | ||
@@ -245,8 +210,3 @@ return { | ||
const definitions = await worker.doDefinition(String(resource), fromPosition(position)); | ||
return definitions == null ? void 0 : definitions.map((definition) => ({ | ||
originSelectionRange: definition.originSelectionRange, | ||
range: toRange(definition.targetRange), | ||
targetSelectionRange: definition.targetSelectionRange, | ||
uri: Uri.parse(definition.targetUri) | ||
})); | ||
return definitions == null ? void 0 : definitions.map(toLocationLink); | ||
} | ||
@@ -473,4 +433,8 @@ }; | ||
languages2.registerCodeActionProvider(languageId, createCodeActionProvider(worker.getWorker)); | ||
createDiagnosticsAdapter(worker.getWorker, defaults); | ||
languages2.setLanguageConfiguration(languageId, richEditConfiguration); | ||
let markerDataProvider = registerMarkerDataProvider({ editor: editor2 }, languageId, createMarkerDataProvider(worker.getWorker)); | ||
defaults.onDidChange(() => { | ||
markerDataProvider.dispose(); | ||
markerDataProvider = registerMarkerDataProvider({ editor: editor2 }, languageId, createMarkerDataProvider(worker.getWorker)); | ||
}); | ||
} | ||
@@ -522,4 +486,5 @@ | ||
createLanguageServiceDefaults, | ||
setDiagnosticsOptions | ||
setDiagnosticsOptions, | ||
yamlDefaults | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "monaco-yaml", | ||
"version": "4.0.0-alpha.2", | ||
"version": "4.0.0-alpha.3", | ||
"description": "YAML plugin for the Monaco Editor", | ||
@@ -8,3 +8,4 @@ "homepage": "https://monaco-yaml.js.org", | ||
"prepack": "node build.js", | ||
"prepare": "husky install" | ||
"prepare": "husky install", | ||
"test": "playwright test" | ||
}, | ||
@@ -46,5 +47,6 @@ "type": "module", | ||
"jsonc-parser": "^3.0.0", | ||
"monaco-marker-data-provider": "^1.0.0", | ||
"monaco-worker-manager": "^2.0.0", | ||
"path-browserify": "^1.0.0", | ||
"prettier": "2.0.5", | ||
"prettier": "^2.0.0", | ||
"vscode-languageserver-textdocument": "^1.0.0", | ||
@@ -59,9 +61,10 @@ "vscode-languageserver-types": "^3.0.0", | ||
"devDependencies": { | ||
"@playwright/test": "^1.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"esbuild": "^0.14.0", | ||
"eslint": "^8.0.0", | ||
"eslint-config-remcohaszing": "^3.0.0", | ||
"eslint-config-remcohaszing": "^4.0.0", | ||
"husky": "^7.0.0", | ||
"lint-staged": "^12.0.0", | ||
"monaco-editor": "^0.31.0", | ||
"monaco-editor": "^0.33.0", | ||
"typescript": "^4.0.0", | ||
@@ -68,0 +71,0 @@ "yaml-language-server": "^1.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
803252
9400
11
10
+ Addedmonaco-marker-data-provider@1.2.4(transitive)
+ Addedmonaco-types@0.1.0(transitive)
+ Addedprettier@2.8.8(transitive)
- Removedprettier@2.0.5(transitive)
Updatedprettier@^2.0.0