Skip to content

Commit

Permalink
Merge pull request #15 from mkslanc/change-mode-fix
Browse files Browse the repository at this point in the history
Changing document mode to unsupported now will not produce errors
  • Loading branch information
anijanyan authored Dec 22, 2022
2 parents 31ba10c + 7b17ebe commit f2d5e85
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ace-linters-root",
"version": "0.0.1",
"version": "0.0.2",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server"
Expand Down
2 changes: 1 addition & 1 deletion packages/ace-linters/build/bundle.ace-linters.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/ace-linters/language-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class LanguageProvider<OptionsType = AceLinters.ServiceOptions> {

// @ts-ignore
this.editor.on("changeMode", () => {
this.$message.changeMode(this.$fileName, this.$mode, this.$options, this.$onInit);
this.$message.changeMode(this.$fileName, this.editor.getValue(), this.$mode, this.$options, this.$onInit);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-linters/message-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export class MessageController {
this.postMessage(message, callback)
}

changeMode(sessionId: string, mode: string, options: AceLinters.ServiceOptions, callback?: () => void) {
this.postMessage(new ChangeModeMessage(sessionId, mode, options), callback);
changeMode(sessionId: string, value: string, mode: string, options: AceLinters.ServiceOptions, callback?: () => void) {
this.postMessage(new ChangeModeMessage(sessionId, value, mode, options), callback);
}

changeOptions(sessionId: string, options: AceLinters.ServiceOptions, callback?: () => void) {
Expand Down
4 changes: 3 additions & 1 deletion packages/ace-linters/message-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ export class ChangeModeMessage extends BaseMessage {
type: MessageType = MessageType.changeMode;
mode: string;
options: ServiceOptions;
value: string;

constructor(sessionId: string, mode: string, options: ServiceOptions) {
constructor(sessionId: string, value: string, mode: string, options: ServiceOptions) {
super(sessionId);
this.value = value;
this.mode = mode;
this.options = options;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/ace-linters/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "ace-linters",
"author": "Azat Alimov <mkslanc@gmail.com>",
"version": "0.0.1",
"version": "0.0.2",
"scripts": {
"build": "webpack"
"clean": "rimraf build",
"build": "npm run clean && webpack --mode=production",
"build-dev": "npm run clean && webpack --mode=development"
},
"dependencies": {
"dev-dependencies": {
"vscode-html-languageservice": "latest",
"vscode-css-languageservice": "latest",
"vscode-json-languageservice": "4.2.1",
Expand Down
16 changes: 9 additions & 7 deletions packages/ace-linters/services/service-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,30 @@ export class ServiceManager {

let document = new Document(documentValue);
let serviceInstance = await this.$getServiceInstanceByMode(mode);
if (!serviceInstance)
return;
serviceInstance.addDocument(sessionID, document, options);
this.$sessionIDToMode[sessionID] = mode;
}

async changeDocumentMode(sessionID: string, mode: string, options: ServiceOptions) {
let service = this.getServiceInstance(sessionID);
let documentValue = service.getDocumentValue(sessionID);
async changeDocumentMode(sessionID: string, value: string, mode: string, options: ServiceOptions) {
this.removeDocument(sessionID);
await this.addDocument(sessionID, documentValue, mode, options);
await this.addDocument(sessionID, value, mode, options);
}

removeDocument(sessionID: string) {
let service = this.getServiceInstance(sessionID);
service.removeDocument(sessionID);
delete this.$sessionIDToMode[sessionID];
if (service) {
service.removeDocument(sessionID);
delete this.$sessionIDToMode[sessionID];
}
}

getServiceInstance(sessionID: string): LanguageService {
let mode = this.$sessionIDToMode[sessionID];
let service = this.findServiceByMode(mode);
if (!mode || !service?.serviceInstance)
throw Error("No registered service for " + sessionID);
return; //TODO:

return service.serviceInstance;
}
Expand Down
18 changes: 9 additions & 9 deletions packages/ace-linters/web.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ ctx.onmessage = async (ev) => {
};
switch (message["type"] as MessageType) {
case MessageType.format:
postMessage["value"] = manager.getServiceInstance(sessionID).format(sessionID, message.value, message.format);
postMessage["value"] = manager.getServiceInstance(sessionID)?.format(sessionID, message.value, message.format);
break;
case MessageType.complete:
postMessage["value"] = await manager.getServiceInstance(sessionID).doComplete(sessionID, message.value);
postMessage["value"] = await manager.getServiceInstance(sessionID)?.doComplete(sessionID, message.value);
break;
case MessageType.resolveCompletion:
postMessage["value"] = await manager.getServiceInstance(sessionID).resolveCompletion(sessionID, message.value);
postMessage["value"] = await manager.getServiceInstance(sessionID)?.resolveCompletion(sessionID, message.value);
break;
case MessageType.change:
manager.getServiceInstance(sessionID).setValue(sessionID, message.value);
manager.getServiceInstance(sessionID)?.setValue(sessionID, message.value);
break;
case MessageType.applyDelta:
manager.getServiceInstance(sessionID).applyDeltas(sessionID, message.value);
manager.getServiceInstance(sessionID)?.applyDeltas(sessionID, message.value);
break;
case MessageType.hover:
postMessage["value"] = await manager.getServiceInstance(sessionID).doHover(sessionID, message.value);
postMessage["value"] = await manager.getServiceInstance(sessionID)?.doHover(sessionID, message.value);
break;
case MessageType.validate:
postMessage["value"] = await manager.getServiceInstance(sessionID).doValidation(sessionID);
postMessage["value"] = await manager.getServiceInstance(sessionID)?.doValidation(sessionID);
break;
case MessageType.init: //this should be first message
await manager.addDocument(sessionID, message.value, message.mode, message.options);
break;
case MessageType.changeMode:
await manager.changeDocumentMode(sessionID, message.mode, message.options);
await manager.changeDocumentMode(sessionID, message.value, message.mode, message.options);
break;
case MessageType.changeOptions:
manager.getServiceInstance(sessionID).setOptions(sessionID, message.options);
manager.getServiceInstance(sessionID)?.setOptions(sessionID, message.options);
break;
case MessageType.dispose:
manager.removeDocument(sessionID);
Expand Down
7 changes: 4 additions & 3 deletions packages/ace-linters/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
let loader;
loader = {
test: /\.(t|j)sx?$/,
Expand All @@ -13,7 +14,7 @@ module.exports = (env, argv) => {
};
return {
cache: false,
devtool: false,
devtool: isProduction ? false : 'inline-source-map',
entry: {
"ace-linters": './index.ts'
},
Expand All @@ -24,7 +25,7 @@ module.exports = (env, argv) => {
test: /\.worker\.ts$/,
loader: 'worker-loader',
options: {
inline: 'no-fallback',
inline: 'no-fallback'
}
}, loader, {
test: /\.css$/,
Expand Down Expand Up @@ -52,7 +53,7 @@ module.exports = (env, argv) => {
}
},
optimization: {
minimize: true,
minimize: isProduction,
splitChunks: false
}
};
Expand Down

0 comments on commit f2d5e85

Please sign in to comment.