from __future__ import annotations
from dataclasses import dataclass
from typing import Dict, Any, List, TypedDict, Callable

import re
import sublime
import Default #type: ignore
import time

from .import core
from .import dap

from .panel import OutputPanel
from .output_view import OutputView

@dataclass
class Problem:
	message: str
	source: dap.SourceLocation

class Position(TypedDict):
	line: int
	character: int|None

class Range(TypedDict):
	start: Position

class Diagnostic(TypedDict):
	range: Range
	severity: int
	message: str

class Diagnostics(TypedDict):
	file: str
	base: str|None
	errors: list[Diagnostic]

class TerminalTask:
	def __init__(self, window: sublime.Window, task: dap.TaskExpanded, on_closed: Callable[[], None]):
		arguments = task.copy()
		name: str
		cmd: str|list[str]|None = arguments.get('cmd')

		if 'name' in arguments:
			name = arguments['name']
		elif isinstance(cmd, str):
			name = cmd
		elif isinstance(cmd, list):