@eclipse-glsp/vscode-integration
Version:
Glue code to integrate GLSP diagrams in VSCode extensions (extension part)
62 lines • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlspEditorProvider = void 0;
const webview_endpoint_1 = require("./webview-endpoint");
/**
* An extensible base class to create a CustomEditorProvider that takes care of
* diagram initialization and custom document events.
*
* Webview setup needs to be implemented.
*/
class GlspEditorProvider {
constructor(glspVscodeConnector) {
this.glspVscodeConnector = glspVscodeConnector;
/** Used to generate continuous and unique clientIds - TODO: consider replacing this with uuid. */
this.viewCount = 0;
this.onDidChangeCustomDocument = glspVscodeConnector.onDidChangeCustomDocument;
}
saveCustomDocument(document, _cancellation) {
return this.glspVscodeConnector.saveDocument(document);
}
saveCustomDocumentAs(document, destination, _cancellation) {
return this.glspVscodeConnector.saveDocument(document, destination);
}
revertCustomDocument(document, _cancellation) {
return this.glspVscodeConnector.revertDocument(document, this.diagramType);
}
backupCustomDocument(_document, context, _cancellation) {
// Basically do the bare minimum - which is nothing
return Promise.resolve({ id: context.destination.toString(), delete: () => undefined });
}
openCustomDocument(uri, _openContext, _token) {
// Return the most basic implementation possible.
return { uri, dispose: () => undefined };
}
async resolveCustomEditor(document, webviewPanel, token) {
// This is used to initialize GLSP for our diagram
const diagramIdentifier = {
diagramType: this.diagramType,
uri: serializeUri(document.uri),
clientId: `${this.diagramType}_${this.viewCount++}`
};
const endpoint = new webview_endpoint_1.WebviewEndpoint({ diagramIdentifier, messenger: this.glspVscodeConnector.messenger, webviewPanel });
// Register document/diagram panel/model in vscode connector
this.glspVscodeConnector.registerClient({
clientId: diagramIdentifier.clientId,
diagramType: diagramIdentifier.diagramType,
document: document,
webviewEndpoint: endpoint
});
this.setUpWebview(document, webviewPanel, token, diagramIdentifier.clientId);
}
}
exports.GlspEditorProvider = GlspEditorProvider;
function serializeUri(uri) {
let uriString = uri.toString();
const match = uriString.match(/file:\/\/\/([a-z])%3A/i);
if (match) {
uriString = 'file:///' + match[1] + ':' + uriString.substring(match[0].length);
}
return uriString;
}
//# sourceMappingURL=glsp-editor-provider.js.map