Skip to content

Commit

Permalink
commands completion
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Dec 17, 2018
1 parent 0925073 commit f64223a
Show file tree
Hide file tree
Showing 5 changed files with 620 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [0.7.6]

- Completion for ObjectScript Commands

## [0.7.4]

- Outline improvements
Expand Down
6 changes: 3 additions & 3 deletions language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"blockComment": ["/*", "*/"]
},
// symbols used as brackets
"brackets": [["{", "}"], ["(", ")"], ["[", "]"]],
"brackets": [["{", "}"], ["(", ")"]],
// symbols that are auto closed when typing
"autoClosingPairs": [["{", "}"], ["(", ")"], ["[", "]"], ["\"", "\""]],
"autoClosingPairs": [["{", "}"], ["(", ")"], ["\"", "\""]],
// symbols that that can be used to surround a selection
"surroundingPairs": [["{", "}"], ["(", ")"], ["\"", "\""], ["[", "]"]],
"surroundingPairs": [["{", "}"], ["(", ")"], ["\"", "\""]],
"indentationRules": {
"increaseIndentPattern": "{",
"decreaseIndentPattern": "}"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-objectscript",
"displayName": "InterSystems ObjectScript",
"description": "InterSystems ObjectScript language support for Visual Studio Code",
"version": "0.7.5",
"version": "0.7.6",
"icon": "images/logo.png",
"categories": [
"Programming Languages",
Expand Down
37 changes: 36 additions & 1 deletion providers/ObjectScriptCompletionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';

import commands = require('./completion/commands.json');
import systemFunctions = require('./completion/systemFunctions.json');
import systemVariables = require('./completion/systemVariables.json');
import structuredSystemVariables = require('./completion/structuredSystemVariables.json');
Expand All @@ -10,6 +11,41 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
position: vscode.Position,
token: vscode.CancellationToken,
context: vscode.CompletionContext
): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
return this.dollarsComplete(document, position) || this.commands(document, position);
}

commands(
document: vscode.TextDocument,
position: vscode.Position
): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
let word = document.getWordRangeAtPosition(position);
let line = document.getText(
new vscode.Range(new vscode.Position(word.start.line, 0), new vscode.Position(word.end.line, word.end.character))
);

if (line.match(/\s+\b[a-z]+\b/i)) {
let search = line.trim().toUpperCase();
let items = commands
.filter(el => el.label.startsWith(search) || el.alias.findIndex(el2 => el2.startsWith(search)) >= 0)
.map(el => ({
...el,
kind: vscode.CompletionItemKind.Keyword,
preselect: el.alias.includes(search),
documentation: new vscode.MarkdownString(el.documentation.join('')),
insertText: el.insertText ? new vscode.SnippetString(el.insertText) : el.label
}));
return {
isIncomplete: items.length > 0,
items
};
}
return null;
}

dollarsComplete(
document: vscode.TextDocument,
position: vscode.Position
): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
let word = document.getWordRangeAtPosition(position);
let line = document.getText(
Expand Down Expand Up @@ -61,7 +97,6 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
.map(el => {
return {
...el,
label: el.label,
kind: vscode.CompletionItemKind.Function,
insertText: new vscode.SnippetString(el.label.replace('$', '\\$') + '($0' + (open ? '' : ')')),
preselect: el.alias.includes(search),
Expand Down
Loading

0 comments on commit f64223a

Please sign in to comment.