Skip to content

Commit c68042a

Browse files
authored
Merge pull request #28 from Kapiainen/array-find-fix
Array find fix
2 parents 51ec72a + 06ccfec commit c68042a

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ Single file build system and a batch build variant.
225225

226226
## **Changelog**
227227

228+
Version 2.6.1 - 2016/MM/DD:
229+
230+
**Skyrim**
231+
- Fixed issue that caused errors when attempting to call *Find* and *RFind* functions on arrays of base types.
232+
- The name of the first argument in the completions for the *Find* and *RFind* functions of arrays now changes based on the array's element type (abElement, afElement, aiElement, asElement, or akElement).
233+
228234
Version 2.6.0 - 2016/05/14:
229235

230236
**Core**

Source/Modules/Skyrim/Linter.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2218,8 +2218,12 @@ def NodeVisitor(self, node, expected = None):
22182218
self.Abort("This script does not have a function/event called '%s'." % node.data.name.value)
22192219
elif expected and expected.type:
22202220
if expected.array:
2221-
script = self.GetCachedScript(expected.type)
2222-
if script:
2221+
validArrayType = None
2222+
if expected.type == self.KW_BOOL or expected.type == self.KW_FLOAT or expected.type == self.KW_INT or expected.type == self.KW_STRING:
2223+
validArrayType = True
2224+
else:
2225+
validArrayType = self.GetCachedScript(expected.type)
2226+
if validArrayType:
22232227
funcName = node.data.name.value.upper()
22242228
if funcName == "FIND":
22252229
func = Statement(self.STAT_FUNCTIONDEF, 0, FunctionDef("INT", "Int", False, "FIND", "Find", [ParameterDef(expected.type, expected.type.capitalize(), False, "AKELEMENT", "akElement", None), ParameterDef("INT", "Int", False, "AISTARTINDEX", "aiStartIndex", Node(self.NODE_EXPRESSION, ExpressionNode(Node(self.NODE_CONSTANT, ConstantNode(Token(self.INT, "0", 0, 0))))))], [self.KW_NATIVE]))

Source/Modules/Skyrim/Plugin.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def on_modified(self, view):
221221
if result.type != sem.KW_SELF:
222222
try:
223223
script = sem.GetCachedScript(result.type)
224-
func = script.functions.get(name, None)
224+
if script:
225+
func = script.functions.get(name, None)
225226
except Linter.SemanticError as e:
226227
return
227228
else:
@@ -831,8 +832,17 @@ def Completions(self, view, prefix, locations):
831832
return completions
832833
elif result.array:
833834
typ = result.type.capitalize()
834-
completions.append(("find\tint func.", "Find(${1:%s akElement}, ${2:Int aiStartIndex = 0})" % typ,))
835-
completions.append(("rfind\tint func.", "RFind(${1:%s akElement}, ${2:Int aiStartIndex = -1})" % typ,))
835+
elementIdentifier = "akElement"
836+
if typ == "Bool":
837+
elementIdentifier = "abElement"
838+
elif typ == "Float":
839+
elementIdentifier = "afElement"
840+
elif typ == "Int":
841+
elementIdentifier = "aiElement"
842+
elif typ == "String":
843+
elementIdentifier = "asElement"
844+
completions.append(("find\tint func.", "Find(${1:%s %s}, ${2:Int aiStartIndex = 0})" % (typ, elementIdentifier),))
845+
completions.append(("rfind\tint func.", "RFind(${1:%s %s}, ${2:Int aiStartIndex = -1})" % (typ, elementIdentifier),))
836846
completions.append(("length\tkeyword", "Length",))
837847
return completions
838848
else:
@@ -961,7 +971,8 @@ def Completions(self, view, prefix, locations):
961971
if result.type != sem.KW_SELF:
962972
try:
963973
script = sem.GetCachedScript(result.type)
964-
func = script.functions.get(name, None)
974+
if script:
975+
func = script.functions.get(name, None)
965976
except Linter.SemanticError as e:
966977
return
967978
else:

0 commit comments

Comments
 (0)