Skip to content

Commit

Permalink
feat: add links to MQL documentation VSCODE-387 (#501)
Browse files Browse the repository at this point in the history
* feat: add links to MQL documentation VSCODE-387

* refactor: remove semicolon

* test: update semicolon in test

* fix: correct system variable link
  • Loading branch information
alenakhineika authored Mar 27, 2023
1 parent 6dfc573 commit 5a8a36c
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 39 deletions.
84 changes: 77 additions & 7 deletions src/language/mongoDBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ export default class MongoDBService {
{
label: 'use',
kind: CompletionItemKind.Function,
documentation: 'Switch current database.',
detail: 'use(<databaseName>)',
preselect: true,
},
];
Expand Down Expand Up @@ -431,6 +433,56 @@ export default class MongoDBService {
}
}

_getAggregationDocumentation({
operator,
description,
}: {
operator: string;
description?: string;
}) {
const title = operator.replace(/[$]/g, '');
const link = `https://www.mongodb.com/docs/manual/reference/operator/aggregation/${title}/`;
return {
kind: MarkupKind.Markdown,
value: description
? `${description}\n\n[Read More](${link})`
: `[Documentation](${link})`,
};
}

_getBsonDocumentation({
bsonType,
description,
}: {
bsonType: string;
description?: string;
}) {
const link = `https://www.mongodb.com/docs/mongodb-shell/reference/data-types/#${bsonType}`;
return {
kind: MarkupKind.Markdown,
value: description
? `${description}\n\n[Read More](${link})`
: `[Documentation](${link})`,
};
}

_getSystemVariableDocumentation({
variable,
description,
}: {
variable: string;
description?: string;
}) {
const title = variable.replace(/[$]/g, '');
const link = `https://www.mongodb.com/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.${title}`;
return {
kind: MarkupKind.Markdown,
value: description
? `${description}\n\n[Read More](${link})`
: `[Documentation](${link})`,
};
}

/**
* Get and cache collection and field names based on the namespace.
*/
Expand Down Expand Up @@ -489,11 +541,14 @@ export default class MongoDBService {

return {
label: item.value,
kind: CompletionItemKind.Keyword,
insertText: snippet,
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Keyword,
documentation: this._getAggregationDocumentation({
operator: item.value,
description: item.description,
}),
preselect: true,
detail: item.description,
};
});
}
Expand Down Expand Up @@ -530,8 +585,11 @@ export default class MongoDBService {
item.meta === 'field:identifier'
? CompletionItemKind.Field
: CompletionItemKind.Keyword,
documentation: this._getAggregationDocumentation({
operator: item.value,
description: item.description,
}),
preselect: true,
detail: item.description,
};
});
}
Expand Down Expand Up @@ -577,8 +635,11 @@ export default class MongoDBService {
item.meta === 'field:identifier'
? CompletionItemKind.Field
: CompletionItemKind.Keyword,
documentation: this._getAggregationDocumentation({
operator: item.value,
description: item.description,
}),
preselect: true,
detail: item.description,
};
});
}
Expand All @@ -600,11 +661,14 @@ export default class MongoDBService {

return {
label: item.value,
kind: CompletionItemKind.Constructor,
insertText: snippet,
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Constructor,
documentation: this._getBsonDocumentation({
bsonType: item.value,
description: item.description,
}),
preselect: true,
detail: item.description,
};
});
}
Expand All @@ -629,8 +693,14 @@ export default class MongoDBService {
item.meta === 'field:reference'
? CompletionItemKind.Reference
: CompletionItemKind.Variable,
documentation:
item.meta === 'variable:system'
? this._getSystemVariableDocumentation({
variable: item.value,
description: item.description,
})
: item.description,
preselect: true,
detail: item.description,
};
});
}
Expand Down
Loading

0 comments on commit 5a8a36c

Please sign in to comment.