Skip to content

Commit

Permalink
feat(commands): add "ansible.server.showMetaData" (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaegassy committed Aug 10, 2022
1 parent a45fd2f commit f23131a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ You can also run the installation command manually.
- `~/AppData/Local/coc/extensions/@yaegassy/coc-ansible-data/ansible/venv/Scripts/yamllint.exe`
- **[Note]** `ansible` is a very large tool and will take some time to install
- `ansible.server.restart`: Restart ansible language server
- `ansible.server.showMetaData`: Show ansible-metadata for ansible language server
- `ansible.ansbileDoc.showInfo`: Run the `ansible-doc` command in a terminal window with various options to display information about the plugins | [DEMO](https://github.com/yaegassy/coc-ansible/pull/22#issuecomment-1178586815)
- `ansible.ansbileDoc.showSnippets`: Run the `ansible-doc` command in a terminal window with various options to display a snippets of the plugins | [DEMO](https://github.com/yaegassy/coc-ansible/pull/22#issuecomment-1178587359)

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@
"command": "ansible.server.restart",
"title": "Restart ansible language server"
},
{
"command": "ansible.server.showMetaData",
"title": "Show ansible-metadata for ansible language server"
},
{
"command": "ansible.ansbileDoc.showInfo",
"title": "Run the `ansible-doc` command in a terminal window with various options to display information about the plugins"
Expand Down
27 changes: 27 additions & 0 deletions src/commands/serverShowMetaData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { commands, ExtensionContext, LanguageClient, NotificationType, workspace } from 'coc.nvim';

export async function activate(context: ExtensionContext, client: LanguageClient) {
await client.onReady();

client.onNotification(new NotificationType(`update/ansible-metadata`), async (ansibleMetaDataList: any) => {
const outputText = JSON.stringify(ansibleMetaDataList, null, 2);

await workspace.nvim
.command(
'belowright vnew ansible-server-metadata | setlocal buftype=nofile bufhidden=hide noswapfile filetype=json'
)
.then(async () => {
const buf = await workspace.nvim.buffer;
buf.setLines(outputText.split('\n'), { start: 0, end: -1 });
});
});

context.subscriptions.push(
commands.registerCommand('ansible.server.showMetaData', async () => {
const { document } = await workspace.getCurrentState();
if (document.languageId !== 'ansible') return;

client.sendNotification(new NotificationType(`update/ansible-metadata`), [document.uri.toString()]);
})
);
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as ansibleDocShowInfoCommandFeature from './commands/ansibleDocShowInfo
import * as ansibleDocShowSnippetsCommandFeature from './commands/ansibleDocShowSnippets';
import * as builtinInstallRequirementsToolsCommandFeature from './commands/builtinInstallRequirementsTools';
import * as serverRestartCommandFeature from './commands/serverRestart';
import * as serverShowMetaDataCommandFeature from './commands/serverShowMetaData';

let client: LanguageClient;
let extensionStoragePath: string;
Expand Down Expand Up @@ -180,6 +181,7 @@ export async function activate(context: ExtensionContext): Promise<void> {

// commands
serverRestartCommandFeature.activate(context, client);
serverShowMetaDataCommandFeature.activate(context, client);
if (pythonCommandPaths) {
builtinInstallRequirementsToolsCommandFeature.activate(context, pythonCommandPaths, client);
}
Expand Down

0 comments on commit f23131a

Please sign in to comment.