Skip to content

Commit

Permalink
Fix exceptions when no or an invalid language is provided #138
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesv committed Jun 10, 2021
1 parent 8743ad0 commit 758f81e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ReSharperPlugin.SpecflowRiderPlugin.Psi
public class GherkinKeywordProvider
{
private readonly Dictionary<string, GherkinKeywordList> _allKeywords = new Dictionary<string, GherkinKeywordList>();

public GherkinKeywordProvider()
{
Initialize();
Expand Down Expand Up @@ -73,8 +74,11 @@ public GherkinKeywordList GetKeywordsList(string language)
if (_allKeywords.TryGetValue(language, out var keywordsList))
return keywordsList;

if (_allKeywords.TryGetValue(language.Substring(0, 2), out var keywordsListLang))
return keywordsListLang;
if (language.Contains("-"))
{
if (_allKeywords.TryGetValue(language.Split('-')[0], out var keywordList))
return keywordList;
}

return _allKeywords["en"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public void Start()

public void UpdateLanguage(string language)
{
if (string.IsNullOrWhiteSpace(language))
return;
_myCurLanguage = language;
_myKeywords = _keywordProvider.GetAllKeywords(language);
}
Expand Down

0 comments on commit 758f81e

Please sign in to comment.