fixes #3931: [php] opening php tag should be recognised as a valid intellisense option
parent
72e4ba9ae2
commit
ee9e74c2ef
|
@ -44,6 +44,7 @@
|
|||
}
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "gulp compile-extension:php && gulp compile-extension:php"
|
||||
"compile": "gulp compile-extension:php",
|
||||
"watch": "gulp watch-extension:php"
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import {CompletionItemProvider, CompletionItem, CompletionItemKind, CancellationToken, TextDocument, Position} from 'vscode';
|
||||
import {CompletionItemProvider, CompletionItem, CompletionItemKind, CancellationToken, TextDocument, Position, Range, TextEdit} from 'vscode';
|
||||
import phpGlobals = require('./phpGlobals');
|
||||
|
||||
export default class PHPCompletionItemProvider implements CompletionItemProvider {
|
||||
|
@ -16,7 +16,10 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
|||
let result: CompletionItem[] = [];
|
||||
var range = document.getWordRangeAtPosition(position);
|
||||
var prefix = range ? document.getText(range) : '';
|
||||
|
||||
if (!range) {
|
||||
range = new Range(position, position);
|
||||
}
|
||||
|
||||
var added : any = {};
|
||||
var createNewProposal = function(kind: CompletionItemKind, name: string, entry: phpGlobals.IEntry) : CompletionItem {
|
||||
var proposal : CompletionItem = new CompletionItem(name);
|
||||
|
@ -35,6 +38,18 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
|||
var matches = (name:string) => {
|
||||
return prefix.length === 0 || name.length >= prefix.length && name.substr(0, prefix.length) === prefix;
|
||||
};
|
||||
|
||||
if (matches('php') && range.start.character >= 2) {
|
||||
let twoBeforePosition = new Position(range.start.line, range.start.character - 2);
|
||||
let beforeWord = document.getText(new Range(twoBeforePosition, range.start));
|
||||
|
||||
if (beforeWord === '<?') {
|
||||
let proposal = createNewProposal(CompletionItemKind.Class, '<?php', null);
|
||||
proposal.textEdit = new TextEdit(new Range(twoBeforePosition, position), '<?php');
|
||||
result.push(proposal);
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
|
||||
for (var name in phpGlobals.globalvariables) {
|
||||
if (phpGlobals.globalvariables.hasOwnProperty(name) && matches(name)) {
|
||||
|
|
Loading…
Reference in New Issue