My final result is:
$i\pi e^{iw}$ for $Im(w)>0$,
$-i\pi e^{iw}$ for $Im(w)<0$.
Notice the missing negative sign in the power of $e$,
and I just can't find any mistake in my proof:
let $w=a+bi$,
then $$\frac{\cos(x)}{x-w}=\frac{\cos(x)}{x-a-bi}=\frac{(x-a+bi)\cos(x)}{(x-a)^2+b^2}=\frac{(x-a)\cos(x)}{(x-a)^2+b^2}+i\frac{b\cos(x)}{(x-a)^2+b^2}$$
then consider the contour integral for the semicircualr closed contour $C:$
$Re^{i\theta}$, $0\leq\theta\leq\pi$ for $b>0$, $\pi\leq\theta\leq 2\pi$ for $b<0$ and the real axis from $-R$ to $R$
$$\lim_{R\to\infty}(\oint_{C}\frac{(z-a)e^{iz}}{(z-a)^2+b^2}\mathrm{d}z,\oint_{C}\frac{be^{iz}}{(z-a)^2+b^2}\mathrm{d}z)=\lim_{R\to\infty}(\pm\oint_{C^\prime}\frac{(z-a)e^{iz}}{(z-a)^2+b^2}\mathrm{d}z\pm\int_{-R}^{R}\frac{(x-a)e^{ix}}{(x-a)^2+b^2}\mathrm{d}x,$$
$$\pm\oint_{C^\prime}\frac{be^{iz}}{(z-a)^2+b^2}\mathrm{d}z\pm\int_{-R}^{R}\frac{be^{ix}}{(x-a)^2+b^2}\mathrm{d}x)=$$
($C\prime$ is the arc of $C$; negative is applied when $b<0$ because we want the clockwise contour to get $\int_{-R}^{R}$)
$$\lim_{R\to\infty}(0\pm\int_{-R}^{R}\frac{(x-a)e^{ix}}{(x-a)^2+b^2}\mathrm{d}x,0\pm\int_{-R}^{R}\frac{be^{ix}}{(x-a)^2+b^2}\mathrm{d}x)$$
by theorem 19.6.2 in Zill's Advanced Engineering Mathematics:
Suppose$f(z)=\frac{P(z)}{Q(z)}$, where the degreee of $P(z)$ is $n$ and the degree of $Q(z)$ is $m\geq n+1$.
If $C_R$ is a semicircular contour $z=Re^{i\theta},0\leq\theta\leq\pi$, and $\alpha>0$, then $\int_{C_R}\frac{P(z)}{Q(z)}e^i\alpha{z}\mathrm{d}z\to 0$ as $R\to\infty$.
Thus by Residue Theorem:
$$\int_{-R}^{R}\frac{(x-a)e^{ix}}{(x-a)^2+b^2}\mathrm{d}x=2\pi{i}\cdot\text{Res}(\frac{(z-a)e^{iz}}{(z-a)^2+b^2},w)=\pi{i}e^{iw}$$
$$\int_{-R}^{R}\frac{be^{ix}}{(x-a)^2+b^2}\mathrm{d}x=2\pi{i}\cdot\text{Res}(\frac{be^{iz}}{(z-a)^2+b^2},w)=\pi e^{iw}$$
Finally:
$$\int_{-\infty}^{\infty}\frac{\cos(x)}{x-w}\mathrm{d}x=\text{Re}(\int_{-\infty}^{\infty}\frac{(x-a)e^{ix}}{(x-a)^2+b^2})+i\text{Re}(\int_{-\infty}^{\infty}\frac{be^{ix}}{(x-a)^2+b^2})=$$
$$\text{Re}(\pi{i}e^{iw})+i\text{Re}(\pi e^{iw})=i\pi e^{iw}\text{ for }b>0,$$ $$\text{Re}(-\pi{i}e^{iw})+i\text{Re}(-\pi e^{iw})=-i\pi e^{iw}\text{ for }b<0$$
I just found out my mistake, so I will post it here in case other poor souls studying complex analysis face the same problem.
Apparently that "Theorem 19.6.2 in Zill's Advanced Engineering Mathematics" has a name:
Also, there is an additional condition where for the semicircular contour in the lower half plane, $\alpha<0$. So we must integrate $$\lim_{R\to\infty}(\oint_{C}\frac{(z-a)e^{-iz}}{(z-a)^2+b^2}\mathrm{d}z,\oint_{C}\frac{be^{-iz}}{(z-a)^2+b^2}\mathrm{d}z)$$ for $b<0$.
Great job Zill, you didn't mention this in your textbook.