Visitar URL original
Support UTF-8 and UTF-16 column units by kaste · Pull Request #2000 · SublimeLinter/SublimeLinter · GitHub
Skip to content

Support UTF-8 and UTF-16 column units - #2000

Merged
kaste merged 1 commit into
masterfrom
column-units
Oct 1, 2026
Merged

kaste merged 1 commit into
masterfrom
column-units

Conversation

@kaste

@kaste kaste commented Sep 30, 2026

Copy link
Copy Markdown
Member

Introduce new configuration attribute column_unit which tells SublimeLinter which unit the linters use for the reported columns.

Converts both endpoints (col, end_col) against the resolved source before clamping. LintMatch coordinates are unchanged as they represent the reported data.

VirtualView actually learned the conversion. Linter gets a new hook convert_column() which authors can use for special needs.

Introduce new configuration attribute `column_unit` which tells
SublimeLinter which unit the linters use for the reported columns.

Converts both endpoints (`col`, `end_col`) against the resolved source
before clamping. LintMatch coordinates are unchanged as they represent
the reported data.

`VirtualView` actually learned the conversion.  `Linter` gets a new
hook `convert_column()` which authors can use for special needs.
@kaste

kaste commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

Justified by a lot of linters that need to implement that on their own. E.g. proposed patch for cpp:

--- a/linter.py
+++ b/linter.py
@@ -16,25 +16,8 @@
 )
 
 
-def byte_offset_to_index(text, offset):
-    """Return the index in `text` of the character at UTF-8 byte `offset`."""
-    return len(text.encode('utf-8')[:offset].decode('utf-8', 'ignore'))
-
-
-class CppcheckBase(Linter):
-    __abstract__ = True
-
-    def reposition_match(self, line, col, m, vv):
-        if col is not None:
-            # cppcheck reports the column as a byte offset into the UTF-8 line,
-            # so every non-ASCII character before the error shifts it. Sublime
-            # counts characters.
-            col = byte_offset_to_index(vv.select_line(line), col)
-
-        return super().reposition_match(line, col, m, vv)
-
-
-class Cppcheck(CppcheckBase):
+class Cppcheck(Linter):
+    column_unit = 'utf8'
     cmd = CMD
     regex = REGEX
     error_stream = util.STREAM_BOTH  # linting errors are on stderr, exceptions like "file not found" on stdout
@@ -49,7 +32,8 @@
     }
 
 
-class CppcheckPlus(CppcheckBase):
+class CppcheckPlus(Linter):
+    column_unit = 'utf8'
     cmd = CMD
     regex = REGEX
     error_stream = util.STREAM_BOTH  # linting errors are on stderr, exceptions like "file not found" on stdout

@kaste
kaste merged commit 9cd3504 into master Oct 1, 2026
9 checks passed
@kaste
kaste deleted the column-units branch October 1, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant