Skip to content

Add language field to /code response #54

@rly0nheart

Description

@rly0nheart

Hey Ben,

Would it be possible to include a language field in the /code API response?

Right now (in searchcode-sdk), I’m manually guessing the language using the whats-that-code library, like this:

language = guess_language_all_methods(code=code_data)
syntax = Syntax(code=code_data, lexer=language, line_numbers=True)

That’s from lines 176–177 in searchcode-sdk/searchcode/cli.py.

However, when using the /search endpoint, each result includes a language key, which makes it easy to apply syntax highlighting directly in the CLI.

For example:

for item in data:
    filename = item.get("filename", "Unknown")
    repo = item.get("repo", "Unknown")
    language = item.get("language", "text")
    lines_count = item.get("linescount", "??")

    code_string = extract_code_string_with_linenumbers(
        lines_dict=item.get("lines", {})
    )

    syntax = Syntax(
        code=code_string, lexer=language, word_wrap=False, indent_guides=True
    )

It’d be super helpful to have that same language field available in the /code response, just to avoid the guesswork. Totally understand if there’s a reason it’s currently excluded. I just thought I’d ask if it might be feasible to include.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions