Consider the commutation relation $[\partial_x, x] = ?$. Adding a test function we would have $$\partial_x (x \Psi) - x \partial_x \Psi = \Psi + x \partial_x \Psi - x \partial_x \Psi = \Psi,$$hence $[\partial_x, x] = 1.$ The canonical commutation relation is therefore suggestive that $\hat p = -i\hbar \partial_x + f(\hat x)$ directly.
One can also imagine that we write out some sort of multinomial expansion, $$\hat F = F(\hat x, \hat p) = \sum_{mn} F_{mn} ~\hat x^m ~\hat p^n.$$
The commutator here is,$$[\hat F, \hat p] = \sum_{mn} F_{mn}~\big(\hat x^m ~\hat p^{n+1} - \hat p~\hat x^m~\hat p^n\big)= \sum_{mn} F_{mn}~[\hat x^m, \hat p]~\hat p^n.$$
Working out this commutator is quite straightforward: $$
\begin{align}
[\hat x^m, \hat p] &= \hat x^m~\hat p - \hat p~\hat x^m\\
&=\hat x~\hat x^{m-1}~\hat p - [\hat p, \hat x]~\hat x^{m-1} - \hat x~\hat p~\hat x^{m-1} \\
&= \hat x [\hat x^{m-1},\hat p] - [\hat p, \hat x]\hat x^{m-1}.
\end{align}$$We can thereby prove by induction,$$[\hat x^m, p] = i\hbar ~m~\hat x^{m-1}.$$Plugging this in above gives $$
i\hbar~\sum_{mn} F_{mn} ~m~\hat x^{m-1}~\hat p^n = i\hbar\frac{\partial}{\partial \hat x} \sum_{mn} F_{mn}~\hat x^m~\hat p^n = i\hbar\frac{\partial\hat F}{\partial \hat x}.$$