Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion common/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Logger {
return new Logger(className)
}

static setup(channel?: LogChannel, logLevel?: LogLevel) {
static setup(channel?: LogChannel, logLevel?: LogLevel): void {
if (channel) {
Logger.logChannel = channel
}
Expand Down
9 changes: 4 additions & 5 deletions common/src/maven/MavenCliProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import * as path from "path"

import * as fs from "fs-extra"
import * as jwtDecode from "jwt-decode"
import jwt_decode from "jwt-decode"

import { BaseEnvironment } from "../platform"
import { MavenInfo } from "../types"

import { Logger, proc } from ".."

const archetypeIdByProjectType: { [key: string]: string } = {
Expand Down Expand Up @@ -148,7 +147,7 @@ export class MavenCliProxy {
private isDiffUserOrTenant(token: { value: string; expirationDate: string }): boolean {
let decodedToken
try {
decodedToken = jwtDecode(token.value)
decodedToken = jwt_decode(token.value)
} catch (e) {
this.logger.warn(`Invalid local SSO authentication token format!`)
return true;
Expand All @@ -175,8 +174,8 @@ export class MavenCliProxy {
// Maven active profile details
const vroUsername = this.environment.getVroUsername() // user@domain
const vroTenant = this.environment.getVroTenant()
return (`${tokenUsername[0]}@${tokenDomain}`.toUpperCase() != vroUsername.toUpperCase() ||

return (`${tokenUsername[0]}@${tokenDomain}`.toUpperCase() != vroUsername.toUpperCase() ||
tokenTenant[0].toUpperCase() != vroTenant.toUpperCase());
}
}
2 changes: 1 addition & 1 deletion common/src/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface CmdResult {
stdout?: string
stderr?: string
}
export function spawn(command: string, args?: string[], options?: cp.SpawnOptions): cp.ChildProcess {
export function spawn(command: string, args: readonly string[], options: cp.SpawnOptions): cp.ChildProcess {
return cp.spawn(command, args, options)
}

Expand Down
4 changes: 2 additions & 2 deletions common/src/rest/VraNgRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class VraNgRestClient {
})
}

private async getAuth(): Promise<object> {
private async getAuth(): Promise<Record<string, unknown>> {
const token = await this.identity.read(this.host)

if (!token) {
Expand Down Expand Up @@ -217,7 +217,7 @@ export class VraNgRestClient {
projectId: string
blueprintId?: string
content?: string
inputs?: object
inputs?: Record<string, unknown>
}): Promise<Deployment> {
return this.send("POST", "/blueprint/api/blueprint-requests", { body })
}
Expand Down
3 changes: 1 addition & 2 deletions common/src/rest/VroRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
WorkflowParam,
WorkflowState
} from "./vro-model"

import { Logger, MavenCliProxy, promise, sleep } from ".."

export class VroRestClient {
Expand All @@ -44,7 +43,7 @@ export class VroRestClient {
return this.settings.activeProfile.getOptional("vro.auth", "basic")
}

private async getAuth(): Promise<object> {
private async getAuth(): Promise<Record<string, unknown>> {
let auth: Auth
switch (this.authMethod.toLowerCase()) {
case "vra":
Expand Down
8 changes: 4 additions & 4 deletions common/src/rest/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type AuthMethod = "basic" | "vra" | "vc" | "vrang"

export interface Auth {
readonly method: AuthMethod
toRequestJson(): object
toRequestJson(): Record<string, unknown>
}

export class Credentials {
Expand All @@ -31,7 +31,7 @@ export class BasicAuth implements Auth {
this.credentials = { username, password }
}

toRequestJson(): object {
toRequestJson(): Record<string, unknown> {
return {
user: this.credentials.username,
pass: this.credentials.password
Expand All @@ -47,7 +47,7 @@ export class VraSsoAuth implements Auth {
this.token = token
}

toRequestJson(): object {
toRequestJson(): Record<string, unknown> {
return {
bearer: this.token
}
Expand All @@ -62,7 +62,7 @@ export class VraNgAuth implements Auth {
this.token = token
}

toRequestJson(): object {
toRequestJson(): Record<string, unknown> {
return {
bearer: this.token
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export abstract class LintCodeActionProvider implements vscode.CodeActionProvide
.filter(diagnostic => diagnostic.source === this.environment.displayName)
.forEach(diagnostic => {
const ruleName = diagnostic.message.split(":")[0]
const ruleCode = diagnostic.code || "unknown-code"
let ruleCode: string = "unknown-code"
if (typeof (diagnostic.code) === "string" || typeof (diagnostic.code) === "number") {
ruleCode = diagnostic.code.toString()
}

if (diagnostic.range.isSingleLine && this.linter.rules[ruleCode]) {
const fixTitle = `Fix: ${ruleName}`
Expand Down
6 changes: 3 additions & 3 deletions extension/src/client/provider/explorer/ExplorerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import {
export class ExplorerProvider implements vscode.TreeDataProvider<AbstractNode>, Registrable, vscode.Disposable {
private readonly logger = Logger.get("ExplorerProvider")

private onDidChangeTreeDataEmitter: vscode.EventEmitter<AbstractNode> = new vscode.EventEmitter<AbstractNode>()
private onDidChangeTreeDataEmitter = new vscode.EventEmitter<AbstractNode | undefined>()
private context: vscode.ExtensionContext
private restClient: VroRestClient
private rootNodes: AbstractNode[] = []
private tree: vscode.TreeView<AbstractNode>

readonly onDidChangeTreeData: vscode.Event<AbstractNode> = this.onDidChangeTreeDataEmitter.event
readonly onDidChangeTreeData: vscode.Event<AbstractNode | undefined> = this.onDidChangeTreeDataEmitter.event

constructor(environment: EnvironmentManager, private config: ConfigurationManager) {
this.restClient = new VroRestClient(config, environment)
Expand All @@ -46,7 +46,7 @@ export class ExplorerProvider implements vscode.TreeDataProvider<AbstractNode>,
})

const refreshCommand = vscode.commands.registerCommand(Commands.RefreshExplorer, () => this.refresh())
const onDidChangeSelection = this.tree.onDidChangeSelection(e => this.onDidChangeSelection(e))
const onDidChangeSelection = this.tree.onDidChangeSelection((e) => this.onDidChangeSelection(e))
const revealItem = vscode.commands.registerCommand(Commands.RevealItemInExplorer, (node: AbstractNode) =>
this.tree.reveal(node)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { PropertyNode } from "./model/leaf/PropertyNode"
export class PropertiesProvider implements vscode.TreeDataProvider<AbstractNode>, Registrable, vscode.Disposable {
private readonly logger = Logger.get("PropertiesProvider")

private onDidChangeTreeDataEmitter: vscode.EventEmitter<AbstractNode> = new vscode.EventEmitter<AbstractNode>()
private onDidChangeTreeDataEmitter = new vscode.EventEmitter<AbstractNode|undefined>()
private rootNode: AbstractNode
private tree: vscode.TreeView<AbstractNode>

readonly onDidChangeTreeData: vscode.Event<AbstractNode> = this.onDidChangeTreeDataEmitter.event
readonly onDidChangeTreeData = this.onDidChangeTreeDataEmitter.event

register(context: vscode.ExtensionContext): void {
this.logger.debug("Registering the properties provider")
Expand Down Expand Up @@ -51,7 +51,7 @@ export class PropertiesProvider implements vscode.TreeDataProvider<AbstractNode>

refresh(node: AbstractNode): void {
this.rootNode = node
this.onDidChangeTreeDataEmitter.fire()
this.onDidChangeTreeDataEmitter.fire(undefined)
}

getTreeItem(element: AbstractNode): Promise<vscode.TreeItem> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/storage/ScopedMemento.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { systemKeychain } from "../system/Keychain"
export class ScopedMemento {
private memento: Memento
private namespace: string
private state: {}
private state: Record<string, any>

private constructor(memento: Memento, namespace: string) {
if (!memento) {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
coveragePathIgnorePatterns: [".*/__tests__/.*", ".*/src/proto/.*", ".*/common/src/rest/.*"],
globals: {
"ts-jest": {
"tsConfig": "<rootDir>/tsconfig.json",
"tsconfig": "<rootDir>/tsconfig.json",
"diagnostics": {
"warnOnly": true
}
Expand Down
100 changes: 7 additions & 93 deletions language-server/src/server/document/Synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

import { AutoWire, Logger } from "vrealize-common"
import { TextDocument, TextDocumentContentChangeEvent, VersionedTextDocumentIdentifier } from "vscode-languageserver"
import { TextDocuments } from "vscode-languageserver"
import { TextDocument } from "vscode-languageserver-textdocument"

import { ConnectionLocator } from "../core"
import { TextDocumentWrapper } from "./TextDocumentWrapper"
Expand All @@ -13,106 +14,19 @@ import { TextDocumentWrapper } from "./TextDocumentWrapper"
@AutoWire
export class Synchronizer {
private readonly logger = Logger.get("Synchronizer")

private textDocuments: Map<string, TextDocumentWrapper> = new Map()
private textDocuments = new TextDocuments(TextDocument)

constructor(connectionLocator: ConnectionLocator) {
connectionLocator.connection.onDidCloseTextDocument(event => {
this.logger.debug(`Document ${event.textDocument.uri} was closed. Removing it from the store.`)
this.textDocuments.delete(event.textDocument.uri)
})

connectionLocator.connection.onDidOpenTextDocument(
async (event): Promise<void> => {
this.logger.debug(`Document ${event.textDocument.uri} was openend. Adding it from the store.`)
await this.doFullSync(event.textDocument, event.textDocument.languageId, event.textDocument.text)
}
)

connectionLocator.connection.onDidChangeTextDocument(
async (event): Promise<void> => {
this.logger.debug(`Document ${event.textDocument.uri} was changed. Refreshing its entry in the store.`)

for (const change of event.contentChanges) {
if (!change) {
continue
}

const oldRichDoc = this.textDocuments.get(event.textDocument.uri)

if (!oldRichDoc) {
continue
}

if (!change.range) {
await this.doFullSync(event.textDocument, oldRichDoc.textDocument.languageId, change.text)
} else {
await this.doIncrementalSync(oldRichDoc.textDocument, event.textDocument, change)
}
}
}
)
this.logger.info("Initilized the Document Synchronizer")
this.textDocuments.listen(connectionLocator.connection)
}

getTextDocument(uri: string): TextDocumentWrapper | null {
const document = this.textDocuments.get(uri)
if (null == document) {
return null
}

return document
}

private applyChangesToTextDocumentContent(
oldDocument: TextDocument,
change: TextDocumentContentChangeEvent
): null | string {
if (null == change.range) {
if (!document) {
return null
}

const startOffset = oldDocument.offsetAt(change.range.start)
const endOffset = oldDocument.offsetAt(change.range.end)
const before = oldDocument.getText().substr(0, startOffset)
const after = oldDocument.getText().substr(endOffset)
return `${before}${change.text}${after}`
}

private async doFullSync(
textDocument: VersionedTextDocumentIdentifier,
languageId: string,
content: string
): Promise<void> {
this.logger.debug(`Performing full sync of ${languageId} document '${textDocument.uri}'`)

const newDocument = TextDocument.create(textDocument.uri, languageId, textDocument.version || -1, content)

this.textDocuments.set(textDocument.uri, new TextDocumentWrapper(newDocument))
}

private async doIncrementalSync(
oldDocument: TextDocument,
newDocument: VersionedTextDocumentIdentifier,
change: TextDocumentContentChangeEvent
): Promise<void> {
if (!change || !change.range) {
return
}

const newContent = this.applyChangesToTextDocumentContent(oldDocument, change)
if (newContent == null) {
return
}

this.logger.debug(`Performing incremental sync of ${oldDocument.languageId} document '${oldDocument.uri}'`)

const newTextDocument = TextDocument.create(
oldDocument.uri,
oldDocument.languageId,
newDocument.version || -1,
newContent
)

this.textDocuments.set(newDocument.uri, new TextDocumentWrapper(newTextDocument))
return new TextDocumentWrapper(document)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/

import { Position, TextDocument } from "vscode-languageserver"
import { Position, TextDocument } from "vscode-languageserver-textdocument"

export class TextDocumentWrapper {
constructor(public readonly textDocument: TextDocument) {}
Expand Down
Loading