Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sublimelinter4 #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions linter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
# Linter for SublimeLinter4, a code checking framework for Sublime Text 3
#
# Written by nirm03
# Copyright (c) 2013 nirm03
Expand All @@ -11,31 +11,12 @@
"""This module exports the Clang plugin class."""

import shlex
from SublimeLinter.lint import Linter, persist
from SublimeLinter.lint import Linter, util
import sublime
import os
import string


def get_project_folder():
proj_file = sublime.active_window().project_file_name()
if proj_file:
return os.path.dirname(proj_file)
# Use current file's folder when no project file is opened.
proj_file = sublime.active_window().active_view().file_name()
if proj_file:
return os.path.dirname(proj_file)
return '.'


def apply_template(s):
mapping = {
"project_folder": get_project_folder()
}
templ = string.Template(s)
return templ.safe_substitute(mapping)


class Clang(Linter):

"""Provides an interface to clang."""
Expand Down Expand Up @@ -75,17 +56,17 @@ def cmd(self):

result = self.base_cmd

if persist.get_syntax(self.view) in ['c', 'c improved']:
if util.get_syntax(self.view) in ['c', 'c improved']:
result += ' -x c '
elif persist.get_syntax(self.view) in ['c++', 'c++11']:
elif util.get_syntax(self.view) in ['c++', 'c++11']:
result += ' -x c++ '

settings = self.get_view_settings()
result += apply_template( settings.get('extra_flags', '') )
result += settings.get('extra_flags', '')

include_dirs = settings.get('include_dirs', [])

if include_dirs:
result += apply_template( ' '.join([' -I ' + shlex.quote(include) for include in include_dirs]) )
result += ' '.join([' -I ' + shlex.quote(include) for include in include_dirs])

return result + ' -'