Skip to content

Commit

Permalink
Don't parse small files
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Atkins-Turkish committed Jun 17, 2016
1 parent cabee6f commit ec1486c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ycm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shutil
import time
import os
import re

from symbol_blacklist import is_valid_symbol
import settings
Expand All @@ -20,6 +21,13 @@
__author__ = 'katharine'


def _newlines_less_than(str, max_newlines):
for n, _ in enumerate(re.finditer('\n', str)):
if n == max_newlines:
return False
return True


class YCM(object):
def __init__(self, files, platform='aplite'):
assert isinstance(files, FileSync)
Expand Down Expand Up @@ -71,7 +79,7 @@ def go_to(self, path, line, ch):
location = result.json()
filepath = location['filepath']
if filepath.startswith(self.files.root_dir):
filepath = filepath[len(self.files.root_dir)+1:]
filepath = filepath[len(self.files.root_dir) + 1:]
else:
return None
return {
Expand All @@ -84,14 +92,18 @@ def parse(self, filepath, line, ch):
self._update_ping()
path = self.files.abs_path(filepath)
with open(path) as f:
contents = f.read()
if _newlines_less_than(contents, 5):
# YCMD complains if you try to parse a file with less than 5 lines.
return None
request = {
'event_name': 'FileReadyToParse',
'filepath': path,
'line_num': line + 1,
'column_num': ch + 1,
'file_data': {
path: {
'contents': f.read(),
'contents': contents,
'filetypes': ['c']
}
}
Expand Down

0 comments on commit ec1486c

Please sign in to comment.