/*
 * Copyright 2010 Jon S Akhtar (Sylvanaar)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sylvanaar.idea.Lua.editor.completion;

import com.intellij.codeInsight.lookup.CharFilter;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.psi.PsiFile;
import com.sylvanaar.idea.Lua.LuaFileType;
import org.jetbrains.annotations.Nullable;

/**
 * Created by IntelliJ IDEA.
 * User: Jon S Akhtar
 * Date: Nov 21, 2010
 * Time: 6:53:07 PM
 */
public class LuaCharFilter extends CharFilter {
    @Nullable
    public Result acceptChar(char c, int prefixLength, Lookup lookup) {
        final PsiFile psiFile = lookup.getPsiFile();
        
        if (psiFile != null && !psiFile.getViewProvider().getLanguages().contains(LuaFileType.LUA_LANGUAGE))
            return null;

        if (Character.isJavaIdentifierPart(c) || c == ':' || c == '[' || c == ']') {
            return Result.ADD_TO_PREFIX;
        }

        if (c == '\n' || c == '\t') {
            return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
        }

        return null;
    }

}

@@ -1131,24 +1131,76 @@
  lookup) %7B%0D%0A
+        if (!lookup.isCompletion()) return null;%0D%0A%0D%0A
         fina
@@ -1470,16 +1470,28 @@
 c == '%5D'
+ %7C%7C c == '.'
 ) %7B%0D%0A   
@@ -1554,37 +1554,144 @@
     
-if (c == '%5Cn' %7C%7C c == '%5Ct') %7B
+switch(c)%7B%0D%0A          case ',':%0D%0A          case ';':%0D%0A          case '=':%0D%0A          case ' ':%0D%0A          case '(':%0D%0A          case '%7B':
 %0D%0A  
@@ -1746,24 +1746,28 @@
 OOKUP;%0D%0A
+%0D%0A  
         
 %7D%0D%0A%0D%0A   
@@ -1750,37 +1750,46 @@
 P;%0D%0A%0D%0A          
-%7D%0D%0A%0D%0A
+default:%0D%0A    
         return n
@@ -1787,21 +1787,46 @@
  return 
-null;
+Result.HIDE_LOOKUP;%0D%0A        %7D
 %0D%0A    %7D%0D

make some corrections to the list of chars that end completion, and allow some certain chars to also end completion, for example the left paren when typing a function call.