Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Adopt new typings and client capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
agusayerza committed Oct 7, 2021
1 parent 6e8bd83 commit 92c8869
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 6,167 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ als.log
.vscode-test/**
.gradle/**
.idea/**
*.code-workspace
*.code-workspace
testFixture/.vscode/
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pipeline {
dockerfile true
}
parameters {
string(name: 'ALS_VERSION', defaultValue: '4.2.0-SNAPSHOT.340', description: 'ALS node client version')
string(name: 'ALS_VERSION', defaultValue: '4.2.0-SNAPSHOT.357', description: 'ALS node client version')
}

environment {
Expand Down
4 changes: 2 additions & 2 deletions install_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ if [ $retVal -ne 0 ]; then
fi


echo "npm i @mulesoft/als-node-client@$ALS_VERSION"
npm i @mulesoft/als-node-client@$ALS_VERSION
echo "npm i @aml-org/als-node-client@$ALS_VERSION"
npm i @aml-org/als-node-client@$ALS_VERSION

retVal=$?
if [ $retVal -ne 0 ]; then
Expand Down
6,056 changes: 33 additions & 6,023 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"command",
"file"
],
"description": "Select how should ALS determine a project configuration, either by `didChangeConfiguration` command or by reading an exchange.json file. For more informaiton please read the [documentation](https://github.com/aml-org/als/blob/7397005c8a17a580c8a102a2537f1a50ca66c965/documentation/features/features.md#als-initialize-params) (Reload required)",
"description": "Select how should ALS determine a project configuration, either by `didChangeConfiguration` command or by reading an exchange.json file. (Reload required)",
"enumDescription": [
"ALS projects can only be configured by using the `didChangeConfiguration`",
"ALS will try to find and read an exchange.json file at the root of the workspace to configure the project."
Expand Down Expand Up @@ -206,6 +206,15 @@
"dark": "path/to/dark/icon.svg"
}
},
{
"command": "als.setMainFile",
"title": "Set as Main File",
"category": "Modifications",
"icon": {
"light": "path/to/light/icon.svg",
"dark": "path/to/dark/icon.svg"
}
},
{
"command": "als.registerProfile",
"title": "Register profile",
Expand All @@ -223,7 +232,8 @@
"light": "path/to/light/icon.svg",
"dark": "path/to/dark/icon.svg"
}
},{
},
{
"command": "als.registerSemantic",
"title": "Register Semantic",
"category": "Modifications",
Expand Down Expand Up @@ -269,6 +279,11 @@
"command": "als.registerProfile",
"group": "7_modification"
},
{
"when": "resourceLangId == aml",
"command": "als.setMainFile",
"group": "7_modification"
},
{
"when": "resourceLangId == aml",
"command": "als.unregisterProfile",
Expand Down Expand Up @@ -305,7 +320,7 @@
}
},
"dependencies": {
"@mulesoft/als-node-client": "4.2.0-SNAPSHOT.340",
"@aml-org/als-node-client": "4.2.0-SNAPSHOT.357",
"@types/mocha": "^8.2.1",
"@types/node": "^11.15.20",
"@types/vscode": "1.52.0",
Expand All @@ -327,5 +342,8 @@
"test-compile": "tsc -p ./",
"pretest": "npm run test-compile",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@aml-org/amf-custom-validator": "0.1.0-SNAPSHOT.16"
}
}
10 changes: 4 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AlsInitializeParamsFeature, ConversionFeature } from './features'
import { AlsLanguageClient } from './server/als'
import { SettingsManager } from './settings'

var jsAls = require.resolve("@mulesoft/als-node-client")
var jsAls = require.resolve("@aml-org/als-node-client")
export let alsLog = vscode.window.createOutputChannel("alsLog");

export class AlsResolver {
Expand All @@ -29,9 +29,6 @@ export class AlsResolver {
}
export async function activate(context: ExtensionContext): Promise<AlsResolver> {
const resolver = new AlsResolver();
//Create output channel
// let alsLog = vscode.window.createOutputChannel("alsLog");

//Write to output.
alsLog.appendLine("Hi! I am alsLog, and I will be your troubleshooting companion for the day. I hope you won't need me!");
await createLanguageClient(alsLog, context).then(alsClient => {
Expand Down Expand Up @@ -81,8 +78,10 @@ async function createLanguageClient(alsLog: vscode.OutputChannel, context: Exten
const settingsManager = new SettingsManager(["amlLanguageServer.run"])
const als = new AlsLanguageClient(languageClient, settingsManager)


const isJVM = runParams.get("platform") === "jvm";
languageClient.registerFeatures([
new AlsInitializeParamsFeature(runParams.get("configurationStyle")),
new AlsInitializeParamsFeature(runParams.get("configurationStyle"), isJVM),
new ConversionFeature()
])

Expand Down Expand Up @@ -125,7 +124,6 @@ function createServer(alsLog: vscode.OutputChannel, context: ExtensionContext):

const jarPath = isLocal ? customPath : `${extensionPath}/lib/als-server.jar`
const jsPath = isLocal ? customPath : jsAls
// const jsPath = require.resolve(`${extensionPath}/lib/node-package/dist/als-node-client.min.js`)

const logFile = logPath !== null ? logPath : `${storagePath}/vscode-aml-language-server.log`

Expand Down
19 changes: 12 additions & 7 deletions src/features.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AlsClientCapabilities, AlsInitializeParams } from '@aml-org/als-node-client';
import { DocumentSelector } from 'vscode';
import { ClientCapabilities, InitializeParams, ServerCapabilities, StaticFeature } from 'vscode-languageclient';
import { AlsInitializeParams, ProjectConfigurationStyles } from './types';
import { ProjectConfigurationStyles } from './types';
export class ConversionFeature implements StaticFeature {
fillInitializeParams?: (params: InitializeParams) => void;
dispose(): void {
Expand All @@ -27,9 +28,9 @@ export class SerializationNotificationFeature implements StaticFeature {
}

export class AlsInitializeParamsFeature implements StaticFeature {
private configurationStyle: ProjectConfigurationStyles = ProjectConfigurationStyles.Command;
constructor(configurationStyle: String) {
switch(configurationStyle) {
private configurationStyle: string = ProjectConfigurationStyles.Command;
constructor(configStyle: String, readonly isJvm: boolean) {
switch(configStyle) {
case ProjectConfigurationStyles.Command:
this.configurationStyle = ProjectConfigurationStyles.Command;
break;
Expand All @@ -40,15 +41,19 @@ export class AlsInitializeParamsFeature implements StaticFeature {
this.configurationStyle = ProjectConfigurationStyles.Command;
break;
}
console.log("ProjectConfigurationStyle: " + this.configurationStyle)
}
fillInitializeParams?: (params: InitializeParams) => void = (params: InitializeParams) => {
var castedParams = params as AlsInitializeParams
castedParams.projectConfigurationStyle = {
style: this.configurationStyle.toString()
style: this.configurationStyle
}
}
fillClientCapabilities(capabilities: ClientCapabilities): void {}
fillClientCapabilities(capabilities: ClientCapabilities): void {
var castedCapabilities = capabilities as AlsClientCapabilities;
castedCapabilities.customValidations = {
enabled: !this.isJvm // Custom validations are not supported in JVM
}
}
initialize(capabilities: ServerCapabilities<any>, documentSelector: DocumentSelector): void {}
dispose(): void {}

Expand Down
18 changes: 13 additions & 5 deletions src/server/als.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@

import * as vscode from 'vscode';
import { RenameFileActionParams, messages, RenameFileActionResult, SerializationParams, SerializationResult, ConversionParams, SerializedDocument, GetWorkspaceConfigurationParams, GetWorkspaceConfigurationResult, DidChangeConfigurationNotificationParams } from '../types';
import { ExecuteCommandRequest, StateChangeEvent } from 'vscode-languageclient';
import { notifyConfig } from './alsConfiguration';
import { FormattingProvider, LANGUAGE_ID } from '../language';
import { LanguageClient } from 'vscode-languageclient/node';
import { conversionHandler, registerProfileHandler, registerSemanticHandler, renameFileHandler, serializationHandler, unregisterProfileHandler, unregisterSemanticHandler } from './handlers';
import { conversionHandler, registerProfileHandler, registerSemanticHandler, renameFileHandler, serializationHandler, setMainFileHandler, unregisterProfileHandler, unregisterSemanticHandler } from './handlers';
import { ConfigurationViewProvider } from '../ui/configurationView';
import { SettingsManager } from '../settings';
import { Disposable } from 'vscode';
import { ConversionParams, DidChangeConfigurationNotificationParams, GetWorkspaceConfigurationParams, GetWorkspaceConfigurationResult, RenameFileActionParams, RenameFileActionResult, SerializationParams, SerializationResult, SerializedDocument } from '@aml-org/als-node-client';
import { messages, ProjectConfigurationStyles } from '../types';


// todo: cleanup all URIs using languageClient.code2ProtocolConverter.asUri(fileUri)
// vscode.Uri with `toString()` causes issues with windows paths
export class AlsLanguageClient {
disposables: Disposable[] = []

configurationStyle: string = vscode.workspace.getConfiguration(`amlLanguageServer.run`).get("configurationStyle")
configurationByCommand: Boolean = this.configurationStyle == ProjectConfigurationStyles.Command

readonly wsConfigTreeViewProvider = new ConfigurationViewProvider(vscode.workspace.workspaceFolders, this)
constructor(readonly languageClient: LanguageClient, private readonly extensionConfigurationManager: SettingsManager) {
this.disposable(vscode.commands.registerCommand("als.renameFile", renameFileHandler(this)))
this.disposable(vscode.commands.registerCommand("als.conversion", conversionHandler(this)))
this.disposable(vscode.commands.registerCommand("als.serialization", serializationHandler(this)))
this.disposable(vscode.commands.registerCommand("als.registerProfile", registerProfileHandler(this)))
this.disposable(vscode.commands.registerCommand("als.unregisterProfile", unregisterProfileHandler(this)))
this.disposable(vscode.commands.registerCommand("als.registerSemantic", registerSemanticHandler(this)))
if(this.configurationByCommand){
this.disposable(vscode.commands.registerCommand("als.setMainFile", setMainFileHandler(this)))
this.disposable(vscode.commands.registerCommand("als.registerProfile", registerProfileHandler(this)))
this.disposable(vscode.commands.registerCommand("als.unregisterProfile", unregisterProfileHandler(this)))
this.disposable(vscode.commands.registerCommand("als.registerSemantic", registerSemanticHandler(this)))
this.disposable(vscode.commands.registerCommand("als.unregisterSemantic", unregisterSemanticHandler(this)))
}
this.disposable(this.languageClient.onDidChangeState(this.languageClientStateListener))
this.disposable(vscode.languages.registerDocumentFormattingEditProvider(LANGUAGE_ID, new FormattingProvider(languageClient)))
this.disposable(vscode.languages.registerDocumentRangeFormattingEditProvider(LANGUAGE_ID, new FormattingProvider(languageClient)))
Expand Down
3 changes: 2 additions & 1 deletion src/server/alsConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AlsConfiguration, messages } from "../types";
import { messages } from "../types";
import { LanguageClient } from "vscode-languageclient/node";
import { workspace } from "vscode";
import { AlsConfiguration } from "@aml-org/als-node-client";


export const initialConfiguration: AlsConfiguration = {
Expand Down
19 changes: 16 additions & 3 deletions src/server/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { AlsLanguageClient } from "./als"
import * as vscode from 'vscode';
import { DidChangeConfigurationNotificationParams, DependencyConfiguration, isDependencyConfiguration } from "../types";
import { awaitInputBox } from "../ui/ui";
import {alsLog} from "../extension"
import { DidChangeConfigurationNotificationParams } from "@aml-org/als-node-client";
import { isDependencyConfiguration } from "../types";

export const setMainFileHandler = (als: AlsLanguageClient) => {
return (fileUri: vscode.Uri) => {
alsLog.appendLine("Setting main file: " + fileUri.toString())
const uri = als.languageClient.code2ProtocolConverter.asUri(fileUri);
als.getWorkspaceConfiguration(uri).then(workspaceConfig => {
const newWorkspaceConfig: DidChangeConfigurationNotificationParams = {
...workspaceConfig.configuration,
mainUri: uri
};
als.changeWorkspaceConfigurationCommand(newWorkspaceConfig);
});
}
}

export const registerProfileHandler = (als: AlsLanguageClient) => {
return (fileUri: vscode.Uri) => {
Expand Down Expand Up @@ -103,8 +118,6 @@ function unregisterDependency(scopeName: string, fileUri: vscode.Uri, als: AlsLa
folder: uri,
dependencies: workspaceConfig.configuration.dependencies
.filter(v => {
// alsLog.appendLine("isDependencyConfiguration " + isDependencyConfiguration(v))
// alsLog.appendLine("scope and uri " + (!isDependencyConfiguration(v) || !(v.scope == scopeName && v.file.toLowerCase() == uri.toLowerCase())))
return !isDependencyConfiguration(v) || !(v.scope == scopeName && v.file.toLowerCase() == uri.toLowerCase());
})
};
Expand Down
11 changes: 6 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export class SettingsManager {
settingRequiresRestart(config: string) {
vscode.workspace.onDidChangeConfiguration(event => {
event.affectsConfiguration(config)
const errMsg = "AML Support configuration has changed and requires a reload.";
const reload: string = "Reload";
vscode.window.showInformationMessage(errMsg, reload).then(async (value?: string) => {
if (value === reload) {
vscode.commands.executeCommand("workbench.action.reloadWindow");
const errMsg = "AML Support configuration has changed and requires a restart.";
const restart: string = "Restart";
vscode.window.showInformationMessage(errMsg, restart).then(async (value?: string) => {
if (value === restart) {
vscode.commands.executeCommand("als.restart");
}
});

})
}
}
3 changes: 2 additions & 1 deletion src/test/e2e/fileRename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, activate, testFilesDirectory, activateExtension } from '../helper';
import { messages, RenameFileActionParams, RenameFileActionResult } from '../../types';
import { messages } from '../../types';
import { RenameFileActionParams, RenameFileActionResult } from '@aml-org/als-node-client';

suite('Should rename file', async function () {
test('Rename file DataType.raml', async () => {
Expand Down
Loading

0 comments on commit 92c8869

Please sign in to comment.