Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strict mode in language server tsconfig file #1278

Merged
merged 1 commit into from
Apr 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TextEdit,
} from "vscode-languageserver";
import { Position, TextDocument } from "vscode-languageserver-textdocument";
import { isScalar, Node, YAMLMap } from "yaml";
import { isNode, isScalar, Node, YAMLMap } from "yaml";
import { IOption } from "../interfaces/module";
import { WorkspaceFolderContext } from "../services/workspaceManager";
import {
Expand Down Expand Up @@ -396,11 +396,8 @@ export async function doCompletion(

// check for 'hosts' keyword and 'ansible_host keyword under vars' to provide inventory auto-completion
let keyPathForHosts: Node[] | null;

if (
new AncestryBuilder(path).parent(YAMLMap).getValue() &&
new AncestryBuilder(path).parent(YAMLMap).getValue()["value"] === null
) {
const element = new AncestryBuilder(path).parent(YAMLMap).getValue();
if (isNode(element) && isScalar(element) && element["value"] === null) {
keyPathForHosts = new AncestryBuilder(path)
.parent(YAMLMap) // compensates for DUMMY MAPPING
.parent(YAMLMap)
Expand All @@ -414,9 +411,12 @@ export async function doCompletion(
const keyNodeForHosts = keyPathForHosts[keyPathForHosts.length - 1];

const conditionForHostsKeyword =
isPlayParam(keyPathForHosts) && keyNodeForHosts["value"] === "hosts";
isPlayParam(keyPathForHosts) &&
isScalar(keyNodeForHosts) &&
keyNodeForHosts["value"] === "hosts";

const conditionForAnsibleHostKeyword =
isScalar(keyNodeForHosts) &&
keyNodeForHosts["value"] === "ansible_host" &&
new AncestryBuilder(keyPathForHosts)
.parent()
Expand Down
34 changes: 17 additions & 17 deletions packages/ansible-language-server/src/utils/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,24 +509,26 @@ export async function findProvidedModule(
}

export function getYamlMapKeys(mapNode: YAMLMap): Array<string> {
return mapNode.items.map((pair) => {
if (pair.key && isScalar(pair.key)) {
return pair.key.value.toString();
}
});
return mapNode.items
.map((pair) => {
if (pair.key && isScalar(pair.key)) {
return String(pair.key.value);
}
})
.filter((e) => !!e) as string[];
}

export function getOrigRange(
node: Node | null | undefined,
): [number, number] | null | undefined {
if (node.range) {
): [number, number] | undefined {
if (node?.range) {
const range = node.range;
return [
range[0] !== undefined ? range[0] : null,
range[1] !== undefined ? range[1] : null,
];
if (range[0] === undefined || range[1] === undefined) {
return undefined;
}
return [range[0], range[1]];
} else {
return [node?.range?.[0], node?.range?.[1]];
return undefined;
}
}

Expand Down Expand Up @@ -569,11 +571,9 @@ export function isPlaybook(textDocument: TextDocument): boolean {
const playbookKeysSet: Set<string> = new Set();
const playbookJSON = path[0].toJSON();

Object.keys(playbookJSON).forEach(function (key) {
if (playbookJSON[key]) {
Object.keys(playbookJSON[key]).forEach((item) =>
playbookKeysSet.add(item),
);
playbookJSON.forEach((item) => {
if (item) {
Object.keys(item).forEach((item) => playbookKeysSet.add(item));
}
});

Expand Down
4 changes: 3 additions & 1 deletion packages/ansible-language-server/test/rootMochaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const mochaHooks = (): Mocha.RootHookObject => {
},

afterEach(this: Mocha.Context) {
console.log(this.currentTest?.title);
if (this.currentTest?.state !== "passed") {
consoleOutput.release();
}
},
};
};
2 changes: 1 addition & 1 deletion packages/ansible-language-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
// "strict": true,
"strict": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down
Loading